Advertisement
mickypinata

GCJ2020-Q4: ESAb ATAd

Apr 4th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int q, len;
  6.  
  7. int main(){
  8.  
  9.     int s, d, x, ask, st, tmp;
  10.     bool cs, cd;
  11.     char c;
  12.  
  13.     scanf("%d %d", &q, &len);
  14.     for(int k = 1; k <= q; ++k){
  15.         vector<int> ans(len + 1, -1);
  16.         vector<int> status(len / 2 + 1, 0); /// Don't Know = 0 Same = 1 Different = 2
  17.         s = 0;
  18.         d = 0;
  19.         ask = 1;
  20.         st = 1; /// st 1 => cout ask st 2 => cout len - ask + 1
  21.         int i = 1;
  22.         while(i <= 150 && ask <= len / 2){
  23.             if(i % 10 == 1){
  24.                 cs = false;
  25.                 cd = false;
  26.                 if(s != 0){
  27.                     cout << s << "\n";
  28.                     fflush(stdout);
  29.                     scanf(" %c", &c);
  30.                     if(c == 'N'){
  31.                         exit(0);
  32.                     }
  33.                     x = c - '0';
  34.                     if(x != ans[s]){
  35.                         cs = true;
  36.                     }
  37.                     ++i;
  38.                 }
  39.                 if(d != 0){
  40.                     cout << d << "\n";
  41.                     fflush(stdout);
  42.                     scanf(" %c", &c);
  43.                     if(c == 'N'){
  44.                         exit(0);
  45.                     }
  46.                     x = c - '0';
  47.                     if(x != ans[d]){
  48.                         cd = true;
  49.                     }
  50.                     ++i;
  51.                 }
  52.                 if(cs || cd){
  53.                     for(int j = 1; j <= len / 2; ++j){
  54.                         if(status[j] == 1 && cs){
  55.                             ans[j] = (1 - ans[j]);
  56.                             ans[len - j + 1] = (1 - ans[len - j + 1]);
  57.                         } else if(status[j] == 2 && cd){
  58.                             ans[j] = (1 - ans[j]);
  59.                             ans[len - j + 1] = (1 - ans[len - j + 1]);
  60.                         }
  61.                     }
  62.                     if(st == 2){
  63.                         st = 1;
  64.                     }
  65.                 }
  66.             }
  67.             if(st == 1){
  68.                 tmp = ask;
  69.             } else if(st == 2){
  70.                 tmp = len - ask + 1;
  71.             }
  72.             cout << tmp << "\n";
  73.             fflush(stdout);
  74.             scanf(" %c", &c);
  75.             if(c == 'N'){
  76.                 exit(0);
  77.             }
  78.             x = c - '0';
  79.             ans[tmp] = x;
  80.             /// Check if Same/Different with its pair
  81.             if(st == 2){
  82.                 if(ans[ask] != x){
  83.                     d = ask;
  84.                     status[ask] = 2;
  85.                 } else {
  86.                     s = ask;
  87.                     status[ask] = 1;
  88.                 }
  89.                 ++ask;
  90.             }
  91.             st = 3 - st;
  92.             ++i;
  93.         }
  94.         for(int i = 1; i <= len; ++i){
  95.             cout << ans[i];
  96.         }
  97.         cout << "\n";
  98.         fflush(stdout);
  99.         scanf(" %c", &c);
  100.         if(c == 'N'){
  101.             exit(0);
  102.         }
  103.     }
  104.  
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement