제출 #1015860

#제출 시각아이디문제언어결과실행 시간메모리
1015860KryzZagrade (COI20_zagrade)C++17
100 / 100
630 ms2668 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ffl cout.flush();
#define phi acos(-1)
#define mr make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pqin priority_queue<ll,vector<ll>,greater<>>
#define pqpair priority_queue<pair<ll,ll> ,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pqpair2 priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pi,pair<ll,ll>>>,greater<pair<pi,pair<ll,ll>>>>
#define INF 1000000009
#define MAXN 300006
#define pii pair<ll,ll>
#define mod 998244353

ll n,k;
ll b[MAXN],h[MAXN];
char c[MAXN];
int main(){
    cin>>n>>k;
    stack<ll> st;
    REP(i,1,n)c[i]='0';
    st.push(1);
    REP(i,2,n){
        if(st.size()==0){
            st.push(i);
            continue;
        }
        ll nw=st.top();
        
        cout<<"? "<<nw<<" "<<i<<endl;
        ffl;
        ll in;
        cin>>in;
        if(in==1){
            c[nw]='(';
            c[i]=')';
            st.pop();
        }
        else{
            st.push(i);
        }
    }
    vector <ll> vec;
    REP(i,1,n){
        if(c[i]=='0')vec.pb(i);
    }
    ll need=vec.size()/2;
    for(auto x : vec){
        if(need){
            c[x]=')';
            need--;
        }
        else{
            c[x]='(';
        }
    }
    cout<<"! ";
    REP(i,1,n)cout<<c[i];
    cout<<endl;
    ffl;
}
/*
 
()(()))()(
 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...