#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
int main() {
ll N,Q;
cin >> N >> Q;
vector<char> ans(N,'-');
ll l=0;
ll r=1;
set<ll> s;
rep(i,N) s.insert(i);
while(1){
if(r>=N) break;
cout << "?" << " " << l+1 << " " << r+1 << endl;
ll q;
cin >> q;
if(q==0){
if(ans[l]=='(') ans[r]='(';
l=r;
r=l+1;
}
if(q==1){
s.erase(l);
s.erase(r);
ans[l]='(';
ans[r]=')';
if(s.size()==0) break;
if((*s.begin())>l){
l=r+1;
r=l+1;
}else{
auto it=s.upper_bound(l);
it--;
l=*it;
r=r+1;
}
}
}
ll cnt=0;
rep(i,N) if(ans[i]=='-') cnt++;
ll now=0;
rep(i,N){
if(ans[i]=='-'){
if(now<cnt/2) ans[i]=')';
if(now>=cnt/2) ans[i]='(';
now++;
}
}
cout << "!" << " ";
rep(i,N) cout << ans[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 |
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 |
5 ms |
600 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
291 ms |
5204 KB |
Output is correct |
3 |
Correct |
567 ms |
5456 KB |
Output is correct |
4 |
Correct |
631 ms |
5208 KB |
Output is correct |
5 |
Correct |
487 ms |
5208 KB |
Output is correct |
6 |
Correct |
552 ms |
5220 KB |
Output is correct |
7 |
Correct |
527 ms |
5208 KB |
Output is correct |
8 |
Correct |
567 ms |
5456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
507 ms |
5208 KB |
Output is correct |
3 |
Correct |
548 ms |
5208 KB |
Output is correct |
4 |
Correct |
508 ms |
5208 KB |
Output is correct |
5 |
Correct |
583 ms |
5208 KB |
Output is correct |
6 |
Correct |
513 ms |
5208 KB |
Output is correct |
7 |
Correct |
538 ms |
5208 KB |
Output is correct |
8 |
Correct |
553 ms |
5208 KB |
Output is correct |