Submission #1003917

#TimeUsernameProblemLanguageResultExecution timeMemory
1003917vjudge1Zagrade (COI20_zagrade)C++17
0 / 100
653 ms2056 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define pii pair<int,int> #define tii tuple<int,int,int,int,int> #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() bool ask(int l, int r){ cout << "? " << l << " " << r << endl; int rt; cin >> rt; return rt; } signed main(){ int n,q; cin >> n >> q; vector<bool> small(n+5,0); vector<char> ans(n+5); for(int i=1; i<n; i++){ small[i] = ask(i,i+1); if(small[i]) ans[i]='(', ans[i+1]=')'; } vector<int> p(n+5,0), s(n+5,0); for(int i=1; i<=n; i++){ p[i] = p[i-1]+1-small[i-1]; } for(int i=n; i>0; i--){ s[i] = s[i+1]+1-small[i]; } int bp=-1; for(int i=1; i<n; i++){ if(p[i]==s[i+1]){ bp=i; break; } } for(int i=0; bp+i<n; i++){ if(small[bp-i] || small[bp+i+1]) break; ans[bp-i]=')'; ans[bp+i+1]='('; } assert(bp!=-1); cout << "! "; for(int i=1; i<=n; i++){ if(ans[i]==')' || ans[i]=='(') cout << ans[i]; else{ if(i<bp) cout << "("; else cout << ")"; } } cout << 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...