#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,q,temp;
ll a,cnt;
stack<ll> st;
char ans[100100];
int main() {
cin >> n >> q;
FOR(1,i,n) {
if(!st.empty()) {
cout << "? " << st.top() << " " << i << endl;
cin >> a;
if(a == 1) {
ans[st.top()] = '(';
ans[i] = ')';
cnt += 2;
st.pop();
}
else {
st.push(i);
}
}
else {
st.push(i);
}
}
cnt = n - cnt;
temp = cnt;
FOR(1,i,n) {
if(temp > cnt/2 && ans[i] != ')' && ans[i] != '(') {
ans[i] = ')';
temp--;
}
else if(ans[i] != ')' && ans[i] != '(') {
ans[i] = '(';
}
}
cout << "! ";
FOR(1,i,n) {
cout << ans[i];
}
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
7 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
10 ms |
208 KB |
Output is correct |
6 |
Correct |
7 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
7 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
9 ms |
208 KB |
Output is correct |
6 |
Correct |
8 ms |
208 KB |
Output is correct |
7 |
Correct |
8 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
206 ms |
324 KB |
Output is correct |
3 |
Correct |
520 ms |
460 KB |
Output is correct |
4 |
Correct |
809 ms |
564 KB |
Output is correct |
5 |
Correct |
654 ms |
368 KB |
Output is correct |
6 |
Correct |
783 ms |
420 KB |
Output is correct |
7 |
Correct |
783 ms |
876 KB |
Output is correct |
8 |
Correct |
765 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
681 ms |
1204 KB |
Output is correct |
3 |
Correct |
787 ms |
536 KB |
Output is correct |
4 |
Correct |
462 ms |
840 KB |
Output is correct |
5 |
Correct |
523 ms |
520 KB |
Output is correct |
6 |
Correct |
659 ms |
900 KB |
Output is correct |
7 |
Correct |
652 ms |
616 KB |
Output is correct |
8 |
Correct |
779 ms |
504 KB |
Output is correct |