# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1106810 | 0pt1mus23 | Zagrade (COI20_zagrade) | C++14 | 4 ms | 592 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert
#define pb push_back
// #define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 5e5 +5, inf = INT_MAX, LL = 30;
int ask(int l,int r){
cout<<"? "<<l<<" "<<r<<endl;
int x;cin>>x;
return x;
}
void rush(){
int n;
cin>>n;
vector<char> ans(n+10,'_');
stack<int> st;
for(int i=1;i<=n;i++){
if(st.empty()){
st.push(i);
}
else{
if(ask(st.top(),i)){
ans[st.top()]='(';
st.pop();
ans[i]=')';
}
else{
st.push(i);
}
}
}
int qal = (st.size())/2;
while(st.size()>qal){
ans[st.top()]='(';
st.pop();
}
while(!st.empty()){
ans[st.top()]=')';
st.pop();
}
string res="";
for(int i=1;i<=n;i++) res+=ans[i];
cout<<"! "<<res<<endl;
}
signed main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
rush();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |