# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1016834 | 8pete8 | Zagrade (COI20_zagrade) | C++17 | 605 ms | 2012 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<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=1e9+7,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,q;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int ask(int l,int r){
cout<<"? "<<l<<" "<<r<<endl;
cout.flush();
int x;cin>>x;
return x;
}
int32_t main(){
fastio
cin>>n>>q;
stack<int>st;
vector<char>ans(n+1,'?');
int cnt=0;
for(int i=1;i<=n;i++){
if(st.empty())st.push(i);
else{
if(ask(st.top(),i))ans[st.top()]='(',ans[i]=')',st.pop(),cnt+=2;
else st.push(i);
}
}
cnt=n-cnt;
cnt/=2;
for(int i=1;i<=n;i++){
if(ans[i]=='?'){
if(cnt)ans[i]=')',cnt--;
else ans[i]='(';
}
}
cout<<"! ";
for(int i=1;i<=n;i++)cout<<ans[i];
}
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... |