Submission #781283

#TimeUsernameProblemLanguageResultExecution timeMemory
781283devariaotaZagrade (COI20_zagrade)C++17
100 / 100
776 ms1328 KiB
#include <bits/stdc++.h> #define int long long #define pb push_back #define pii pair<int, int> #define fr first #define sc second #define query(l, r) cout << "? " << l << " " << r << endl; cin >> res; using namespace std; const int N = 1e5 + 5; string ans; bool res; signed main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); int n, q; cin >> n >> q; ans.assign(n, ' '); stack<int> s; s.push(1); int cnt = 0; for (int i = 2; i <= n; i++) { if (s.empty()) { s.push(i); continue; } int cur = s.top(); query(cur, i); if (res) { ans[cur - 1] = '('; ans[i - 1] = ')'; cnt++; s.pop(); } else s.push(i); } int cntfrr = n / 2 - cnt; for (int i = 0; i < n; i++) { if (ans[i] == ' ') { if (cntfrr) { ans[i] = ')'; cntfrr--; } else ans[i] = '('; } } cout << "! " << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...