답안 #391664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391664 2021-04-19T13:22:34 Z ronnith Zagrade (COI20_zagrade) C++14
100 / 100
1166 ms 5320 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] = ')';
			int values = -1;
			set<int>::iterator ptr;
			if(crr != pos.begin()) {
				ptr = crr;
				ptr --;
				values = *ptr;
			} else {
				if(it != (--pos.end())) {
					ptr = it;
					ptr ++;
					values = *ptr;
				}
			}
			pos.erase(crr);
			pos.erase(it);
			if(values != -1) {
				it = pos.find(values);
			}
		}
		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] = ')';
			it ++;
		}
		while(it != pos.end()) {
			ans[(*it)-1] = '(';
			it ++;
		}
	}
	string out = ans;
	cout << "! " << out << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 5 ms 328 KB Output is correct
3 Correct 8 ms 328 KB Output is correct
4 Correct 12 ms 328 KB Output is correct
5 Correct 14 ms 328 KB Output is correct
6 Correct 14 ms 328 KB Output is correct
7 Correct 13 ms 328 KB Output is correct
8 Correct 7 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 13 ms 332 KB Output is correct
3 Correct 6 ms 328 KB Output is correct
4 Correct 14 ms 328 KB Output is correct
5 Correct 13 ms 328 KB Output is correct
6 Correct 14 ms 328 KB Output is correct
7 Correct 13 ms 328 KB Output is correct
8 Correct 12 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 308 ms 5128 KB Output is correct
3 Correct 1045 ms 5164 KB Output is correct
4 Correct 1119 ms 5164 KB Output is correct
5 Correct 943 ms 5256 KB Output is correct
6 Correct 693 ms 5320 KB Output is correct
7 Correct 703 ms 5100 KB Output is correct
8 Correct 1166 ms 5060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1157 ms 5108 KB Output is correct
3 Correct 970 ms 5252 KB Output is correct
4 Correct 1092 ms 5180 KB Output is correct
5 Correct 830 ms 5172 KB Output is correct
6 Correct 855 ms 5240 KB Output is correct
7 Correct 827 ms 5260 KB Output is correct
8 Correct 846 ms 5184 KB Output is correct