#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char f[N];
int n,x,pr[N],nx[N];
main () {
cin>>n;
for (int i=0; i<=n+1; i++)
nx[i]=i+1,pr[i]=i-1;
int l=1,r=2,L,R,ans=n/2;
while (l<=n && r<=n) {
cout<<"? "<<l<<" "<<r<<endl;
cin>>x;
if (x) {
--ans;
f[l]='(',f[r]=')';
if (1<=pr[l]) {
L=pr[l],R=nx[r];
nx[L]=R,pr[R]=L;
l=L,r=R;
}
else {
L=nx[r],R=nx[nx[r]];
pr[L]=pr[l];
l=L,r=R;
}
}
else {
L=r,R=nx[r];
l=L,r=R;
}
}
for (int i=1; i<=n; i++)
if (f[i]!='(' && f[i]!=')') {
if (ans>0)
f[i]=')',--ans;
else
f[i]='(';
}
cout<<"! ";
for (int i=1; i<=n; i++)
cout<<f[i];
cout<<endl;
}
Compilation message
zagrade.cpp:10:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main () {
| ^
zagrade.cpp: In function 'int main()':
zagrade.cpp:49:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
49 | for (int i=1; i<=n; i++)
| ^~~
zagrade.cpp:51:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
51 | cout<<endl;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Incorrect |
6 ms |
364 KB |
Mismatch at position 2. Expected (, found ) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Mismatch at position 2. Expected (, found ) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |