제출 #1112164

#제출 시각아이디문제언어결과실행 시간메모리
1112164vako_pZagrade (COI20_zagrade)C++14
100 / 100
1900 ms3716 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back

const int mxN = 1e6 + 5;
ll n,a[mxN],q;
stack<ll> st;
char ch[] = {'(', ')'};

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> q;
	st.push(1);
	ll cnt = n / 2;
	for(int i = 2; i <= n; i++){
		ll l = st.top();
		cout << "? " << l << ' ' << i << endl;
		ll ans;
		cin >> ans;
		if(ans){
			a[l] = 1;
			a[i] = 2;
			st.pop();
			cnt--;
		}
		else st.push(i);
		if(st.empty()) st.push(++i);
	}
	cout << "! ";
	ll val = 2;
	for(int i = 1; i <= n; i++){
		if(a[i] == 0){
			cnt--;
			a[i] = val;
			if(cnt == 0) val = 1;
		}
		cout << ch[a[i] - 1];
	}
	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...