# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1003770 | vjudge1 | Zagrade (COI20_zagrade) | C++17 | 588 ms | 1368 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>
using namespace std;
int main(){
int n,q; cin >> n >> q;
string res = string(n, '?');
stack<int> ultimo;
int i=1;
while(i<n){
cout << "? "<< i << ' '<< i+1 << endl;
int ans; cin >> ans;
if(ans == 1){
res[i-1] = '('; res[i]=')';
i = i+2;
while(ultimo.size()!=0 and i<= n){
cout << "? "<< ultimo.top()<< ' '<< i << endl;
int outro; cin >> outro;
if(outro == 1){
res[ultimo.top()-1]='('; res[i-1] = ')';
i++; ultimo.pop();
}
else break;
}
}
else{
ultimo.push(i); i++;
}
}
int falta=0;
for(auto j: res) if(j == '?') falta++;
int qnt = 0;
for(int j=0; j<res.size(); j++){
if(res[j] != '?')continue;
if(qnt <(falta/2)) res[j] = ')';
else res[j] = '(';
qnt++;
}
cout << "! "<< res << endl;
}
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... |