#include<bits/stdc++.h>
#define sherina ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define int long long
#define INF 1e18
using namespace std;
int n , q;
stack < int > st;
char ans[200005];
signed main(){
cin >> n >> q;
st.push(1);
for(int i = 2 ; i <= n ; i++){
if(st.empty()){
st.push(i);
continue;
}
cout << "? " << st.top() << " " << i << endl;
int anss; cin >> anss;
if(anss){
ans[st.top()] = '(';
ans[i] = ')';
st.pop();
}
else st.push(i);
}
if(st.size() >= 1){
for(int i = 1 ; i <= n / 2 ; i++){
if(ans[i] != ')' && ans[i] != '(') ans[i] = ')';
}
for(int i = n/2 ; i >= 1 ; i--){
if(ans[i] != ')' && ans[i] != '(') ans[i] = '(';
}
}
cout << "! ";
for(int i = 1 ; i <= n ; i++) cout << ans[i];
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
8 ms |
208 KB |
Output is correct |
6 |
Correct |
6 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Mismatch at position 2. Expected (, found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
283 ms |
368 KB |
Output is correct |
3 |
Correct |
577 ms |
500 KB |
Output is correct |
4 |
Correct |
706 ms |
472 KB |
Output is correct |
5 |
Correct |
662 ms |
380 KB |
Output is correct |
6 |
Correct |
661 ms |
472 KB |
Output is correct |
7 |
Correct |
641 ms |
788 KB |
Output is correct |
8 |
Correct |
536 ms |
372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Mismatch at position 3. Expected (, found |
2 |
Halted |
0 ms |
0 KB |
- |