Submission #391659

# Submission time Handle Problem Language Result Execution time Memory
391659 2021-04-19T13:12:54 Z ronnith Zagrade (COI20_zagrade) C++14
0 / 100
3000 ms 4928 KB
#include <bits/stdc++.h>

using namespace std;

int n, q;

inline bool query(int l, int r) {
	cout << "? " << l << ' ' << r << endl;
	bool res;
	cin >> res;
	return res;
}

int main() {
	cin >> n >> q;
	set<int> pos;
	for(int i = 1;i <= n;i ++) {
		pos.insert(i);
	}
	char ans[n+1];
	ans[n] = '\0';
	auto it = pos.begin();
	while(it != (--pos.end())) {
		auto crr = (it++);
		if(query(*crr, *it)) {
			ans[(*crr) - 1] = '(';
			ans[(*it) - 1] = ')';
			pos.erase(it);
			it = (crr--);
			pos.erase(it);
			it = crr;
		}
		if((int)pos.size() == 0) {
			break;
		}
	}
	if((int)pos.size()) {
		it = pos.begin();
		for(int rep = 0;rep < (int)pos.size() / 2;rep ++) {
			ans[(*it)-1] = ')';
		}
		while(it != pos.end()) {
			ans[(*it)-1] = '(';
		}
	}
	string out = ans;
	cout << "! " << out << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Execution timed out 3072 ms 328 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 200 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Execution timed out 3077 ms 4928 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3053 ms 200 KB Time limit exceeded
2 Halted 0 ms 0 KB -