#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
bool ask(int l, int r){
int val;
cout<<"? "<<l<<' '<<r<<endl;
cin>>val;
return val;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n, q;
cin>>n>>q;
int a=n/2,b=n/2;
vector<int>Ans(n+1), stk;
for(int i=1;i<=n;i++){
if(stk.empty()){
stk.push_back(i);
}
else{
bool val=ask(stk.back(), i);
if(val){
Ans[stk.back()]=1, Ans[i]=2;
stk.pop_back();
a--, b--;
}
else{
stk.push_back(i);
}
}
}
cout<<"! ";
for(int i=1;i<=n;i++){
char c;
if(Ans[i]){
c='('+Ans[i]-1;
}
else{
if(a)
c=')', a--;
else
c='(';
}
cout<<c;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
456 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Correct |
6 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
306 ms |
832 KB |
Output is correct |
3 |
Correct |
591 ms |
832 KB |
Output is correct |
4 |
Correct |
597 ms |
828 KB |
Output is correct |
5 |
Correct |
612 ms |
828 KB |
Output is correct |
6 |
Correct |
554 ms |
828 KB |
Output is correct |
7 |
Correct |
577 ms |
1508 KB |
Output is correct |
8 |
Correct |
568 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
611 ms |
1532 KB |
Output is correct |
3 |
Correct |
630 ms |
1416 KB |
Output is correct |
4 |
Correct |
574 ms |
1496 KB |
Output is correct |
5 |
Correct |
555 ms |
1468 KB |
Output is correct |
6 |
Correct |
589 ms |
1580 KB |
Output is correct |
7 |
Correct |
609 ms |
1376 KB |
Output is correct |
8 |
Correct |
618 ms |
1088 KB |
Output is correct |