#include<bits/stdc++.h>
using namespace std;
int n,q;
int query(int le, int ri)
{
if((ri-le+1)%2==1)
return 0;
cout<<"? "<<le<<" "<<ri<<endl;
int aux;
cin>>aux;
return aux;
}
char rez[100005];
signed main()
{
cin>>n>>q;
int cnt=n/2;
deque<int> dq;
for(int i=1;i<=n;i++)
{
dq.push_back(i);
if((int)dq.size()>=2 && query(dq[(int)dq.size()-2],dq.back()))
{
rez[dq[(int)dq.size()-2]] = '(';
rez[dq[(int)dq.size()-1]] = ')';
dq.pop_back();
dq.pop_back();
cnt--;
}
}
for(int i=0;i<cnt;i++)
{
rez[dq[i]]=')';
rez[dq[(int)dq.size()-i-1]]='(';
}
cout<<"! ";
for(int i=1;i<=n;i++)
cout<<rez[i];
cout<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
4 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 |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
600 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
440 KB |
Output is correct |
7 |
Correct |
6 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 |
257 ms |
952 KB |
Output is correct |
3 |
Correct |
530 ms |
1220 KB |
Output is correct |
4 |
Correct |
506 ms |
1248 KB |
Output is correct |
5 |
Correct |
486 ms |
964 KB |
Output is correct |
6 |
Correct |
529 ms |
1272 KB |
Output is correct |
7 |
Correct |
494 ms |
1472 KB |
Output is correct |
8 |
Correct |
537 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
510 ms |
2028 KB |
Output is correct |
3 |
Correct |
535 ms |
1288 KB |
Output is correct |
4 |
Correct |
524 ms |
1520 KB |
Output is correct |
5 |
Correct |
534 ms |
1328 KB |
Output is correct |
6 |
Correct |
498 ms |
1876 KB |
Output is correct |
7 |
Correct |
514 ms |
1708 KB |
Output is correct |
8 |
Correct |
490 ms |
1008 KB |
Output is correct |