This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
// #define endl '\n'
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int ll
typedef long long ll;
using namespace std;
const int N = 200000 + 10;
bool vis[N];
signed main() {
FAST;
int n, q;
cin >> n >> q;
stack<int> st;
st.push(0);
vis[0] = 1;
for(int i = 1; i < n; i++) {
if(!st.size()) st.push(i);
else {
cout << "? " << st.top() + 1 << ' ' << i + 1 << endl;
int x;
cin >> x;
if(x == 1) st.pop();
else {
st.push(i);
vis[i] = 1;
}
}
}
string s = "";
for(int i = 0; i < n; i++) {
if(vis[i]) s += "(";
else s += ")";
}
cout << "! " << s << endl;
return 0;
}
# | 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... |