Advertisement
he_obviously

Untitled

Jul 21st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #pragma comment(linker, "/STACK:367077216")
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <queue>
  9. #include <algorithm>
  10. #include <iomanip>
  11.  
  12. using namespace std;
  13.  
  14. typedef long long ll;
  15. typedef long double ld;
  16.  
  17. #define pii pair<int, int>
  18. #define F first
  19. #define S second
  20. #define all(x) (x).begin(),(x).end()
  21. #define pb push_back
  22. #define pop pop_back
  23.  
  24. int main() {
  25.  
  26.     ios_base::sync_with_stdio(0);
  27.     cin.tie(0); cout.tie(0);
  28.  
  29.     int n;
  30.     cin >> n;
  31.  
  32.     vector<int> v = { 1 };
  33.     vector<char> a(n + 1, '-');
  34.     a[1] = '(';
  35.  
  36.     int f = 1, last = 1;
  37.     while (last < n && f < n) {
  38.         if (v.empty()) {
  39.             a[f] = '(';
  40.             last = f;
  41.             v.push_back(f);
  42.         }
  43.         else {
  44.             cout << "? " << f << " " << last + 1 << "\n";
  45.             fflush(stdout);
  46.             string s;
  47.             cin >> s;
  48.             if (s == "Yes") {
  49.                 a[last + 1] = ')';
  50.                 v.pop_back();
  51.                 if (!v.empty()) {
  52.                     f = v.back();
  53.                     last += 1;
  54.                 }
  55.                 else {
  56.                     f = last + 2;
  57.                 }
  58.             }
  59.             else {
  60.                 v.push_back(last + 1);
  61.                 a[last + 1] = '(';
  62.                 f = last + 1;
  63.                 last += 1;
  64.             }
  65.         }
  66.     }
  67.  
  68.     cout << "! ";
  69.     for (int i = 1; i <= n; ++i)
  70.         cout << a[i];
  71.     cout << "\n";
  72.     fflush(stdout);
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement