Submission #1149430

#TimeUsernameProblemLanguageResultExecution timeMemory
1149430PwoZagrade (COI20_zagrade)C++20
100 / 100
223 ms1492 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, q;
char ch[100005];
vector<int> st;

int ask(int i, int j) {
	cout << "? " << i << ' ' << j << endl;
	int res; cin >> res;
	return res;
}

int32_t main() {
	cin >> n >> q;
	for (int i = 1; i <= n; i++) ch[i] = '.';
	int j = 1;
	while (j <= n) {
		if (st.empty()) st.push_back(j++);
		if (j > n) break;
		int res = ask(st.back(), j);
		if (res) {
			ch[st.back()] = '(';
			ch[j] = ')';
			st.pop_back();
		} else st.push_back(j);
		j++;
	}

	int cnt = 0;
	for (int i = 1; i <= n; i++) if (ch[i] == ')') cnt++;
	string s = "";
	for (int i = 1; i <= n; i++) {
		if (ch[i] != '.') s += ch[i];
		else if (cnt * 2 < n) {
			s += ')';
			cnt++;
		} else s += '(';
	}
	cout << "! " << s << 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...