Submission #641576

#TimeUsernameProblemLanguageResultExecution timeMemory
641576makanhuliaZagrade (COI20_zagrade)C++17
14 / 100
3093 ms5448 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n, q; cin >> n >> q; vector<int> ans(n, -1); set<int> s; s.insert(0); for(int i = 1; i < n; i++) { if(ans[i] != -1) continue; // cout << "Masuk " << i << '\n'; while(!s.empty()) { int l = *s.rbegin(), r = i; if(l >= 0 && r < n) { cout << "? " << l + 1 << " " << r + 1 << endl; int x; cin >> x; if(x) { ans[l] = 1; ans[r] = 0; s.erase(l); i++; } else { s.insert(r); break; } } else { break; } } if(s.empty() && ans[i] == -1) s.insert(i); } for(int i = 0; i < n; i++) { if(ans[i] != -1) { int l = i - 1, r = i + 1; while(l >= 0 && ans[l] != -1) l--; while(r < n && ans[r] != -1) r++; if(l < 0 || r >= n) continue; while(l >= 0) { ans[l--] = 0; ans[r++] = 1; } } } bool all = 1; for(int i = 0; i < n; i++) { all &= ans[i] == -1; } if(all) { int l = n / 2 - 1, r = n / 2; while(l >= 0) { ans[l--] = 0; ans[r++] = 1; } } cout << "! "; for(int i = 0; i < n; i++) { assert(ans[i] != -1); if(ans[i]) cout << '('; else cout << ')'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...