Advertisement
ccbeginner

UVa Q665

Feb 16th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. //UVa Q665
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. struct check{
  6.     bool l[100] = {0};
  7.     bool r[100] = {0};
  8.     char res;
  9. };
  10.  
  11. int32_t main(){
  12.     int t;
  13.     cin >> t;
  14.     while(t--){
  15.         int n, k;
  16.         cin >> n >> k;
  17.         check arr[100];
  18.         for(int i = 0; i < k; ++i){
  19.             int p;
  20.             cin >> p;
  21.             for(int j = 0; j < p; ++j){
  22.                 int x;
  23.                 cin >> x;
  24.                 arr[i].l[x] = 1;
  25.             }
  26.             for(int j = 0; j < p; ++j){
  27.                 int x;
  28.                 cin >> x;
  29.                 arr[i].r[x] = 1;
  30.             }
  31.             cin >> arr[i].res;
  32.         }
  33.         int ans = -1;
  34.         for(int i = 1; i <= n && ans; ++i){
  35.             bool ok = 1;
  36.             int big = 0;
  37.             for(int j = 0; j < k && ok; ++j){
  38.                 //cout << ' ' << arr[j].res << ' ' << big << '\n';
  39.                 if(arr[j].res == '=' && (arr[j].l[i] || arr[j].r[i]))ok = 0;
  40.                 else if((arr[j].res == '<' && arr[j].r[i]) || (arr[j].res == '>' && arr[j].l[i])){
  41.                     if(big == -1)ok = 0;
  42.                     else big = 1;
  43.                 }else if((arr[j].res == '>' && arr[j].r[i]) || (arr[j].res == '<' && arr[j].l[i])){
  44.                     if(big == 1)ok = 0;
  45.                     else big = -1;
  46.                 }
  47.             }
  48.             //cout << ok << ' ' << big << '\n';
  49.             if(ok){
  50.                 if(ans != -1)ans = 0;
  51.                 else ans = i;
  52.             }
  53.         }
  54.         cout << ans << '\n';
  55.         if(t)cout << '\n';
  56.     }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement