#include<bits/stdc++.h>
#define sherina ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define int long long
#define INF 1e18
using namespace std;
int n , q;
stack < int > st;
char ans[200005];
signed main(){
int buka = 0;
cin >> n >> q;
st.push(1);
for(int i = 0 ; i <= n ; i++) ans[i] = '*';
for(int i = 2 ; i <= n ; i++){
if(st.empty()){
st.push(i);
continue;
}
cout << "? " << st.top() << " " << i << endl;
int anss; cin >> anss;
if(anss){
ans[st.top()] = '(';
ans[i] = ')';
buka++;
st.pop();
}
else st.push(i);
}
if(st.size() >= 1){
for(int i = 1 ; i <= n ; i++){
if(buka == n / 2) break;
if(ans[i] != ')' && ans[i] != '('){
ans[i] = ')';
buka++;
}
}
for(int i = n ; i >= 1 ; i--){
if(ans[i] != ')' && ans[i] != '(') ans[i] = '(';
}
}
cout << "! ";
for(int i = 1 ; i <= n ; i++) cout << ans[i];
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
256 KB |
Output is correct |
4 |
Correct |
7 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
5 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
228 KB |
Output is correct |
3 |
Correct |
4 ms |
308 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
9 ms |
304 KB |
Output is correct |
6 |
Correct |
6 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
308 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 |
351 ms |
336 KB |
Output is correct |
3 |
Correct |
595 ms |
396 KB |
Output is correct |
4 |
Correct |
771 ms |
336 KB |
Output is correct |
5 |
Correct |
669 ms |
336 KB |
Output is correct |
6 |
Correct |
689 ms |
336 KB |
Output is correct |
7 |
Correct |
656 ms |
868 KB |
Output is correct |
8 |
Correct |
627 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
730 ms |
1148 KB |
Output is correct |
3 |
Correct |
846 ms |
460 KB |
Output is correct |
4 |
Correct |
546 ms |
904 KB |
Output is correct |
5 |
Correct |
717 ms |
596 KB |
Output is correct |
6 |
Correct |
602 ms |
792 KB |
Output is correct |
7 |
Correct |
596 ms |
552 KB |
Output is correct |
8 |
Correct |
765 ms |
384 KB |
Output is correct |