# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
559101 | Redhood | Zagrade (COI20_zagrade) | C++14 | 762 ms | 848 KiB |
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 fi first
#define se second
#define sz(x) (int)(x).size()
#define pb push_back
#define mkp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
bool ask(int i , int j){
cout << "? " << i + 1 << ' ' << j + 1 << endl;
int ans;
cin >> ans;
return ans;
}
signed main(){
int n , q;
cin >> n >> q;
stack < int > pos;
pos.push(0);
string s = string(n, '(');
int did=0;
int need = n / 2;
// cout << s << endl;
for(int i = 1; i < n; ++i){
if(pos.empty()){
pos.push(i);
continue;
}
int f = pos.top();
if(ask(f , i)){
s[f] = '(';
s[i] = ')';
did++;
pos.pop();
}else{
pos.push(i);
}
}
assert(sz(pos) % 2 == 0);
int f = sz(pos) / 2;
for(int t=0;t<f;++t){
s[pos.top()] = '(';
pos.pop();
}
for(int t=0;t<f;++t){
s[pos.top()] = ')';
pos.pop();
}
cout << "! " << s << endl;
return 0;
}
Compilation message (stderr)
# | 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... |