MrSairam

doesnotwork

Apr 10th, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int B;
  5.  
  6. int query(int i) {
  7.   // cout << i << endl;
  8.   printf("%d\n", i);
  9.   int r;
  10.   scanf("%d", &r);
  11.   return r;
  12. }
  13.  
  14. void test_case() {
  15.   vector<int> answer(B + 1);
  16.   int L = 1, R = B;
  17.   for(int nr = 1; true; nr += 2) {
  18.     if(nr % 10 == 1 && nr != 1) {
  19.       int found = -1;
  20.       int found_diff = -1;
  21.       for(int i = 1; i < L; ++i) {
  22.         if(answer[i] == answer[B+1-i]) {
  23.           found = i;
  24.         }
  25.         else {
  26.           found_diff = i;
  27.         }
  28.       }
  29.       if(found == -1) {
  30.         int new_value = query(1);
  31.         query(1);
  32.         if(new_value != answer[1]) {
  33.           for(int i = 1; i <= L; ++i) {
  34.             answer[i] ^= 1;
  35.           }
  36.           for(int i = R; i <= B; ++i) {
  37.             answer[i] ^= 1;
  38.           }
  39.         }
  40.       }
  41.       else {
  42.         int one = query(found);
  43.         if(one != answer[found]) {
  44.           for(int i = 1; i <= L; ++i) {
  45.             answer[i] ^= 1;
  46.           }
  47.           for(int i = R; i <= B; ++i) {
  48.             answer[i] ^= 1;
  49.           }
  50.         }
  51.         if(found_diff == -1) {
  52.           query(found);
  53.         }
  54.         else {
  55.           if(query(found_diff) != answer[found_diff]) {
  56.             reverse(answer.begin() + 1, answer.end());
  57.           }
  58.         }
  59.       }
  60.       nr += 2;
  61.     }
  62.     answer[L] = query(L);
  63.     answer[R] = query(R);
  64.     L++;
  65.     R--;
  66.     if(L > R) {
  67.       for(int i = 1; i <= B; ++i) {
  68.         cout << answer[i];
  69.       }
  70.       cout << endl;
  71.       string response;
  72.       cin >> response;
  73.       assert(response == "Y");
  74.       return;
  75.     }
  76.   }
  77. }
  78.  
  79. int main() {
  80.   int T;
  81.   scanf("%d%d", &T, &B);
  82.   for(int nr = 1; nr <= T; nr++) {
  83.     // printf("Case #%d: ", nr);
  84.     test_case();
  85.   }
  86. }
Add Comment
Please, Sign In to add comment