#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back
const int mxN = 1e6 + 5;
ll n,a[mxN],q;
stack<ll> st;
char ch[] = {'(', ')'};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
st.push(1);
ll cnt = n / 2;
for(int i = 2; i <= n; i++){
ll l = st.top();
cout << "? " << l << ' ' << i << endl;
ll ans;
cin >> ans;
if(ans){
a[l] = 1;
a[i] = 2;
st.pop();
cnt--;
}
else st.push(i);
if(st.empty()) st.push(++i);
}
cout << "! ";
ll val = 2;
for(int i = 1; i <= n; i++){
if(a[i] == 0){
cnt--;
a[i] = val;
if(cnt == 0) val = 1;
}
cout << ch[a[i] - 1];
}
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
9 ms |
336 KB |
Output is correct |
3 |
Correct |
16 ms |
464 KB |
Output is correct |
4 |
Correct |
15 ms |
608 KB |
Output is correct |
5 |
Correct |
15 ms |
336 KB |
Output is correct |
6 |
Correct |
18 ms |
600 KB |
Output is correct |
7 |
Correct |
14 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
16 ms |
584 KB |
Output is correct |
3 |
Correct |
16 ms |
504 KB |
Output is correct |
4 |
Correct |
15 ms |
468 KB |
Output is correct |
5 |
Correct |
14 ms |
336 KB |
Output is correct |
6 |
Correct |
14 ms |
464 KB |
Output is correct |
7 |
Correct |
15 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
889 ms |
3088 KB |
Output is correct |
3 |
Correct |
1814 ms |
2684 KB |
Output is correct |
4 |
Correct |
1755 ms |
2688 KB |
Output is correct |
5 |
Correct |
1712 ms |
3160 KB |
Output is correct |
6 |
Correct |
1752 ms |
2936 KB |
Output is correct |
7 |
Correct |
1810 ms |
3380 KB |
Output is correct |
8 |
Correct |
1746 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1823 ms |
1404 KB |
Output is correct |
3 |
Correct |
1774 ms |
3716 KB |
Output is correct |
4 |
Correct |
1861 ms |
3132 KB |
Output is correct |
5 |
Correct |
1802 ms |
3708 KB |
Output is correct |
6 |
Correct |
1900 ms |
3392 KB |
Output is correct |
7 |
Correct |
1869 ms |
3064 KB |
Output is correct |
8 |
Correct |
1780 ms |
2688 KB |
Output is correct |