#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 |
208 KB |
Output is correct |
2 |
Correct |
6 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
7 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 |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
320 ms |
696 KB |
Output is correct |
3 |
Correct |
976 ms |
696 KB |
Output is correct |
4 |
Correct |
783 ms |
720 KB |
Output is correct |
5 |
Correct |
597 ms |
696 KB |
Output is correct |
6 |
Correct |
682 ms |
700 KB |
Output is correct |
7 |
Correct |
540 ms |
1172 KB |
Output is correct |
8 |
Correct |
636 ms |
700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |