#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=(1<<16);
int main()
{
int n,q;
cin>>n>>q;
stack<int> st;
st.push(1);
int ans[n+1];
memset(ans,-1,sizeof ans);
for (int i = 2; i <= n; ++i)
{
if(!st.empty()){
cout <<"? "<< st.top() << " " << i<<endl;
int c;
cin>>c;
if(c==1){
ans[st.top()]=0;
ans[i]=1;
st.pop();
}else st.push(i);
}else st.push(i);
}
int m=st.size();
for (int i = 0; i < m/2; ++i)
{
ans[st.top()]=0;
st.pop();
}
for (int i = 0; i < m/2; ++i)
{
ans[st.top()]=1;
st.pop();
}
cout << "! ";
for (int i = 1; i <= n; ++i)
{
if(ans[i]==1) cout <<")";
else cout <<"(";
}cout <<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
340 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
289 ms |
600 KB |
Output is correct |
3 |
Correct |
560 ms |
600 KB |
Output is correct |
4 |
Correct |
511 ms |
600 KB |
Output is correct |
5 |
Correct |
515 ms |
600 KB |
Output is correct |
6 |
Correct |
554 ms |
852 KB |
Output is correct |
7 |
Correct |
585 ms |
1420 KB |
Output is correct |
8 |
Correct |
572 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
563 ms |
1572 KB |
Output is correct |
3 |
Correct |
549 ms |
1368 KB |
Output is correct |
4 |
Correct |
528 ms |
1400 KB |
Output is correct |
5 |
Correct |
568 ms |
1336 KB |
Output is correct |
6 |
Correct |
569 ms |
1340 KB |
Output is correct |
7 |
Correct |
602 ms |
1344 KB |
Output is correct |
8 |
Correct |
564 ms |
600 KB |
Output is correct |