Submission #641591

#TimeUsernameProblemLanguageResultExecution timeMemory
641591bonkZagrade (COI20_zagrade)C++14
100 / 100
1002 ms960 KiB
#include <bits/stdc++.h> using namespace std; int ask(int a, int b){ cout << "? " << a << " " << b << endl; int ret; cin >> ret; return ret; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; vector<char>ans(n + 1, '#'); stack<int>st; int cnt = 0; for(int i = 1; i <= n; i++){ if(st.empty()){ st.push(i); continue; } int x = st.top(); if(ask(x, i)){ cnt += 2; ans[x] = '('; ans[i] = ')'; st.pop(); } else{ st.push(i); } } int unused = n - cnt; int tmp = unused; cout << "! "; for(int i = 1; i <= n; i++){ if(ans[i] == '#'){ if(tmp > unused/2) ans[i] = ')'; else ans[i] = '('; tmp--; } cout << ans[i]; } cout << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...