Submission #581624

#TimeUsernameProblemLanguageResultExecution timeMemory
581624penguinhackerZagrade (COI20_zagrade)C++17
0 / 100
817 ms840 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1e5; int n, q, match[mxN]; bool qry(int l, int r) { cout << "? " << l+1 << " " << r+1 << endl; bool res; cin >> res; return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> q; memset(match, -1, sizeof(match)); string ans(n, '0'); for (int i=1; i<n;) { // right bound of current bracket sequence if (qry(i-1, i)) { // found match[i-1]=i, match[i]=i-1; ans[i-1]='(', ans[i]=')'; int j=i-1; if (j&&match[j-1]!=-1) { j=match[j-1]; match[i]=j, match[j]=i; } while(j&&i+1<n&&qry(j-1, i+1)) { ++i, --j; match[i]=j, match[j]=i; ans[j]='(', ans[i]=')'; if (j&&match[j-1]!=-1) j=match[j-1]; } i+=2; } else ++i; } int cnt=count(ans.begin(), ans.end(), '('); for (int i=0; i<n; ++i) if (ans[i]=='0') { if (cnt<n/2) ans[i]=')', ++cnt; else ans[i]='('; } cout << "! " << ans << 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...