Submission #1152411

#TimeUsernameProblemLanguageResultExecution timeMemory
1152411YSH2020Zagrade (COI20_zagrade)C++20
0 / 100
0 ms416 KiB
#include <bits/stdc++.h>
using namespace std;


int ans[1000005];
void solve(int s, int e) {
  //suppose this means the start wont make a bracket sequence with anything else between s and e. 
  while (e-s > 1) {
    cout << '?' << ' ' << s+1 << ' ' << s+2 << '\n';
    int x; cin >> x;
    if (x == 1) {
      ans[s+1] = 1;
      ans[s+2] = 0;
      s += 2;
    }
    else {
      ans[s+1] = 0;
      ans[e-1] = 1;
      s++;
      e--;
    }
  }
}


int main() {
  int n, q; cin >> n >> q;
  //suppose this is a valid bracket sequence.
  ans[0] = 0;
  ans[n-1] = 1;
  int last = 0;
  for (int i = 1; i < n; i += 2) {
    cout << "? " << last+1 << ' ' << i+1 << '\n';
    int x; cin >> x;
    if (x == 1) {
      solve(last, x);
      last = x+1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == 0) cout << '(';
    else cout << ')';
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...