#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,q;
cin >> n >> q;
char ans[n+5];
for (int i=1;i<=n;i++){
ans[i] = '?';
}
stack<ll> s;
s.push(1);
ll count=0;
ll curr=2;
while (curr<=n){
if (s.empty()) {
s.push(curr);
curr++;
}
ll x = s.top();
s.pop();
cout << "? " << x << ' ' << curr << endl;
ll a;
cin >> a;
if (a==1){
ans[x] = '(';
ans[curr] = ')';
count += 2;
}
else{
s.push(x);
s.push(curr);
}
curr++;
}
cout << "! ";
ll left = n-count;
left /= 2;
for (int i=1;i<=n;i++){
if (ans[i]=='?'){
if (left>0) cout << ')';
else cout << '(';
left--;
}
else cout << ans[i];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |