Submission #781311

#TimeUsernameProblemLanguageResultExecution timeMemory
781311makanhuliaZagrade (COI20_zagrade)C++17
100 / 100
728 ms1440 KiB
# 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...