#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define tii tuple<int,int,int,int,int>
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
vector<char> ans;
int n;
bool ask(int l, int r){
cout << "? " << l << " " << r << endl;
int rt; cin >> rt;
return rt;
}
void solve(int l, int r){
if(r<l) return;
for(int i=l+1; i<=r; i+=2){
if(ask(l,i)){
ans[l]='(';
ans[i]=')';
solve(l+1,i-1);
solve(i+1,r);
break;
}
}
return;
}
signed main(){
int q; cin >> n >> q;
ans.resize(n+1);
solve(1,n);
cout << "! ";
for(int i=1; i<=n; i++) cout << ans[i];
cout << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Correct |
13 ms |
344 KB |
Output is correct |
4 |
Correct |
20 ms |
344 KB |
Output is correct |
5 |
Correct |
31 ms |
344 KB |
Output is correct |
6 |
Correct |
50 ms |
344 KB |
Output is correct |
7 |
Correct |
751 ms |
680 KB |
Output is correct |
8 |
Correct |
26 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Mismatch at position 1. Expected ), found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
288 ms |
344 KB |
Output is correct |
3 |
Runtime error |
553 ms |
508 KB |
Execution killed with signal 13 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Mismatch at position 1. Expected ), found |
2 |
Halted |
0 ms |
0 KB |
- |