This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
# define int long long
# define vi vector<int>
# define pb push_back
# define pii pair<int, int>
# define fi first
# define se second
# define endl '\n'
using namespace std;
char ans[100005];
bool ask(int a, int b) {
cout << "? " << a << " " << b << endl << flush;
int ret; cin >> ret;
return ret;
}
void solve() {
int n, q;
cin >> n >> q;
stack<int> s;
s.push(1);
int cnt=0;
for(int i=1; i<=n; i++) ans[i]='-';
for(int i=2; i<=n; i++) {
if(s.empty()) {
s.push(i);
continue;
}
if(ask(s.top(), i)) {
ans[s.top()]='(';
ans[i]=')';
cnt++;
s.pop();
} else {
s.push(i);
}
}
int tmp=(n/2)-cnt;
for(int i=1; i<=n; i++) {
if(ans[i]=='-') {
if(tmp>0) {
ans[i]=')';
tmp--;
} else ans[i]='(';
}
}
cout << "! ";
for(int i=1; i<=n; i++) cout << ans[i];
cout << endl << flush;
}
signed main() {
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |