Advertisement
Guest User

Untitled

a guest
Jun 13th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define endl "\n"
  5. #pragma GCC optimize(3, "Ofast", "inline")
  6. typedef vector<int> vi;
  7. const int INF = 2e9;
  8. #define yesnosolve cout << (solve() ? "NO" : "YES") << endl
  9.  
  10. char q1(int pos)
  11. {
  12.     char c;
  13.     cout << "? 1 " << pos + 1 << endl
  14.          << flush;
  15.     scanf("%s", &c);
  16.     return c;
  17. }
  18.  
  19. int q2(int pos1, int pos2)
  20. {
  21.     int ans;
  22.     cout << "? 2 " << pos1 + 1 << ' ' << pos2 + 1 << endl
  23.          << flush;
  24.     cin >> ans;
  25.     return ans;
  26. }
  27.  
  28. void solve()
  29. {
  30.     int len;
  31.     cin >> len;
  32.     vector<char> res(len, '?');
  33.  
  34.     res[0] = q1(0);
  35.     // cerr << res[0] << endl
  36.     //      << flush;
  37.     // cerr << len << '-' << endl;
  38.     for (int i = 1; i < len; i++)
  39.     {
  40.         cerr << i << '-' << endl;
  41.         set<char> st;
  42.         bool f = false;
  43.         for (int j = i - 1; j >= 0; j--)
  44.         {
  45.             st.insert(res[j]);
  46.             if (q2(j, i) == int(st.size()))
  47.             {
  48.                 res[i] = res[j];
  49.                 f = true;
  50.                 break;
  51.             }
  52.         }
  53.  
  54.         if (!f)
  55.             res[i] = q1(i);
  56.  
  57.         cerr << i << '-' << endl;
  58.     }
  59.  
  60.     cout << "! ";
  61.     for (auto &a : res)
  62.         cout << a;
  63.     cout << endl
  64.          << flush;
  65. }
  66.  
  67. int main()
  68. {
  69.     // cin.tie(nullptr);
  70.     // cout.tie(nullptr);
  71.     // ios_base::sync_with_stdio(0);
  72.  
  73.     // int T;
  74.     // cin >> T;
  75.     // while (T--)
  76.     solve();
  77.  
  78.     return 0;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement