#include <bits/stdc++.h>
using namespace std;
char C_[500005];
int n_,q_,x_,pr_[500005],nx_[500005];
int main () {
cin>>n_>>q_; // ;(((((((((((((((((((((((((((((( qqqqqqq
for (int i=1; i<=n_+3; i++)
nx_[i]=i+1,pr_[i]=i-1,C_[i]='.';
int l_=1,r_=2,L_=l_,R_=r_,ans_=n_/2;
while (1<=L_ && L_<=n_ && 1<=R_ && R_<=n_ && L_<=R_) {
l_=L_,r_=R_;
cout<<"? "<<l_<<" "<<r_<<endl;
cin>>x_;
if (x_) {
--ans_;
C_[l_]='(',C_[r_]=')';
if (nx_[r_]>n_) break;
if (1<=pr_[l_]) {
L_=pr_[l_];
R_=nx_[r_];
nx_[L_]=R_;
pr_[R_]=L_;
}
else {
if (nx_[nx_[r_]]>n_) break;
L_=nx_[r_],R_=nx_[nx_[r_]];
pr_[L_]=0;
}
}
else {
if (nx_[r_]>n_) break;
assert(nx_[l_]==r_);
L_=nx_[l_],R_=nx_[r_];
pr_[L_]=l_;
nx_[L_]=R_;
pr_[R_]=L_;
}
}
for (int i=1; i<=n_; i++)
if (C_[i]=='.') {
if (ans_>0)
C_[i]=')',--ans_;
else
C_[i]='(';
}
cout<<"! ";
for (int i=1; i<=n_; i++)
cout<<C_[i];
cout<<endl;
}
Compilation message
zagrade.cpp: In function 'int main()':
zagrade.cpp:56:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
56 | for (int i=1; i<=n_; i++)
| ^~~
zagrade.cpp:58:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
58 | cout<<endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
5 ms |
364 KB |
Output is correct |
3 |
Correct |
8 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
5 |
Correct |
10 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
364 KB |
Output is correct |
7 |
Correct |
7 ms |
364 KB |
Output is correct |
8 |
Correct |
8 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
384 KB |
Output is correct |
3 |
Correct |
8 ms |
364 KB |
Output is correct |
4 |
Correct |
8 ms |
364 KB |
Output is correct |
5 |
Correct |
8 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
7 |
Correct |
10 ms |
364 KB |
Output is correct |
8 |
Correct |
8 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
342 ms |
1284 KB |
Output is correct |
3 |
Correct |
822 ms |
1260 KB |
Output is correct |
4 |
Correct |
725 ms |
1260 KB |
Output is correct |
5 |
Correct |
682 ms |
1260 KB |
Output is correct |
6 |
Correct |
805 ms |
1284 KB |
Output is correct |
7 |
Correct |
944 ms |
1260 KB |
Output is correct |
8 |
Correct |
902 ms |
1388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
797 ms |
1388 KB |
Output is correct |
3 |
Correct |
902 ms |
1260 KB |
Output is correct |
4 |
Correct |
955 ms |
1260 KB |
Output is correct |
5 |
Correct |
646 ms |
1260 KB |
Output is correct |
6 |
Correct |
880 ms |
1260 KB |
Output is correct |
7 |
Correct |
894 ms |
1388 KB |
Output is correct |
8 |
Correct |
906 ms |
1260 KB |
Output is correct |