Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.08 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cassert>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <iostream>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. using namespace std;
  12.  
  13. #define pb push_back
  14. #define st first
  15. #define nd second
  16.  
  17. typedef vector<int> vi;
  18. typedef vector<vi> vvi;
  19. typedef pair<int, int> ii;
  20. typedef vector<ii> vii;
  21.  
  22. char c;
  23. int T, B;
  24.  
  25. void solve_lte_10() {
  26.     vector<char> v(B+1);
  27.     for (int i = 1; i <= B; ++i) {
  28.         cout << i << endl;
  29.         cin >> v[i];
  30.     }
  31.     string s = "";
  32.     for (int i = 1; i <= B; ++i) {
  33.         s += v[i];
  34.     }
  35.     cout << s << endl;
  36.     cin >> c;
  37. }
  38.  
  39. int main() {
  40.     ios_base::sync_with_stdio(false);
  41.     cin >> T >> B;
  42.     for (int t = 1; t <= T; ++t) {
  43.         if (B <= 10) {
  44.             solve_lte_10();
  45.             continue;
  46.         }
  47.         vector<int> v(B+1);
  48.         int idx_eq = -1, idx_dif = -1;
  49.  
  50.         // First 5 pairs
  51.         int i = 1, j = B;
  52.         for (; i <= 5; ++i, --j) {
  53.             int xi, xj;
  54.             cout << i << endl;
  55.             cin >> xi;
  56.             cout << j << endl;
  57.             cin >> xj;
  58.             v[i] = xi;
  59.             v[j] = xj;
  60.             if (idx_eq == -1 && xi == xj) idx_eq = i;
  61.             if (idx_dif == -1 && xi != xj) idx_dif = j;
  62.         }
  63.  
  64.         assert(i <= j);
  65.  
  66.         while (i <= j) {
  67.             // inicio rodada
  68.             int iini = i, jini = j;
  69.             int xeq, xdif;
  70.             if (idx_eq != -1) {
  71.                 cout << idx_eq << endl;
  72.                 cin >> xeq;
  73.                 cout << idx_eq << endl;
  74.                 cin >> xeq;
  75.             }
  76.             if (idx_dif != -1) {
  77.                 cout << idx_dif << endl;
  78.                 cin >> xdif;
  79.                 cout << idx_dif << endl;
  80.                 cin >> xdif;
  81.             }
  82.             if (idx_dif == -1 || idx_eq == -1) { // tudo igual ou tudo diferente
  83.                 if ((idx_eq != -1 && xeq == v[idx_eq]) || (idx_dif != -1 && xdif == v[idx_dif])) { // continuou igual
  84.                     // faz nada
  85.                 } else {
  86.                     // not de todos os anteriores
  87.                     for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
  88.                         v[aux_i] = 1-v[aux_i];
  89.                         v[aux_j] = 1-v[aux_j];
  90.                     }
  91.                 }
  92.             } else { // tem ambos iguais e diferentes
  93.                 if (xeq == v[idx_eq] && xdif == v[idx_dif]) { // continuou igual
  94.                     // faz nada
  95.                 } else if (xeq != v[idx_eq] && xdif != v[idx_dif]) { // ambos mudaram
  96.                     // not de todos os anteriores
  97.                     for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
  98.                         v[aux_i] = 1-v[aux_i];
  99.                         v[aux_j] = 1-v[aux_j];
  100.                     }
  101.                 } else if (xeq == v[idx_eq] && xdif != v[idx_dif]) { // par igual continuou e par diferente mudou
  102.                     for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
  103.                         swap(v[aux_i], v[aux_j]);
  104.                     }
  105.                 } else { // par igual mudou e par diferente continuou
  106.                     for (int aux_i = 1, aux_j = B; aux_i < iini; ++aux_i, --aux_j) {
  107.                         v[aux_i] = 1-v[aux_i];
  108.                         v[aux_j] = 1-v[aux_j];
  109.                         swap(v[aux_i], v[aux_j]);
  110.                     }
  111.  
  112.                 }
  113.             }
  114.             for (int k = 0; i <= j && k < 4; ++k, ++i, --j) {
  115.                 int xi, xj;
  116.                 cout << i << endl;
  117.                 cin >> xi;
  118.                 cout << j << endl;
  119.                 cin >> xj;
  120.                 v[i] = xi;
  121.                 v[j] = xj;
  122.                 if (idx_eq == -1 && xi == xj) idx_eq = i;
  123.                 if (idx_dif == -1 && xi != xj) idx_dif = j;
  124.             }
  125.             // final rodada
  126.         }
  127.         string s = "";
  128.         for (int i = 1; i <= B; ++i)
  129.             s += ((char)(v[i])+'0');
  130.         cout << s << endl;
  131.         cin >> c;
  132.     }
  133.     return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement