Submission #1152431

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


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


int main() {
  int n, q; cin >> n >> q;
  //suppose this is a valid bracket sequence.
  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, i);
      last = i+1;
    }
  }
  cout << "! ";
  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...