# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1148704 | Tyx2019 | Zagrade (COI20_zagrade) | C++20 | 232 ms | 1356 KiB |
#include <bits/stdc++.h>
#define int long long
#define debug(x) if(1) cout << #x << " is " << x << endl;
using namespace std;
const int INF = 1e18;
void solve(){
int N, Q;
cin >> N >> Q;
char res[N+5];
for(int i=1;i<=N;i++) res[i] = '?';
int cur = 1;
stack<int> stk;
stk.push(1);
for(int i=2;i<=N;i++){
stk.push(i);
if(stk.size() < 2) continue;
int b = stk.top();
stk.pop();
int a = stk.top();
stk.pop();
cout << "? " << a << " " << b << endl;
int bruh;
cin >> bruh;
if(bruh == 1){
res[a] = '(';
res[b] = ')';
}
else{
stk.push(a);
stk.push(b);
}
}
int cnt = 0;
for(int i=1;i<=N;i++)cnt += (res[i] == '?');
//debug(cnt);
int bruh = cnt / 2;
cnt = 0;
for(int i=1;i<=N;i++){
cnt += (res[i] == '?');
if(res[i] != '?') continue;
if(cnt <= bruh) res[i] = ')';
else res[i] = '(';
}
cout << "! ";
for(int i=1;i<=N;i++) cout << res[i];
cout << endl;
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
}
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... |