답안 #581640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581640 2022-06-23T00:13:54 Z penguinhacker Zagrade (COI20_zagrade) C++17
100 / 100
912 ms 800 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int mxN=1e5;
int n, q, match[mxN];
 
bool qry(int l, int r) {
	cout << "? " << l+1 << " " << r+1 << endl;
	bool res;
	cin >> res;
	return res;
}
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	memset(match, -1, sizeof(match));
	string ans(n, '0');
	for (int i=1; i<n;) { // right bound of current bracket sequence
		if (qry(i-1, i)) { // found
			match[i-1]=i, match[i]=i-1;
			ans[i-1]='(', ans[i]=')';
			int j=i-1;
			if (j&&match[j-1]!=-1) {
				j=match[j-1];
				match[i]=j, match[j]=i;
			}
			while(j&&i+1<n&&qry(j-1, i+1)) {
				++i, --j;
				match[i]=j, match[j]=i;
				ans[j]='(', ans[i]=')';
				if (j&&match[j-1]!=-1) {
					j=match[j-1];
					match[i]=j, match[j]=i;
				}
			}
			i+=2;
		} else
			++i;
	}
	int cnt=count(ans.begin(), ans.end(), '(');
	for (int i=0; i<n; ++i)
		if (ans[i]=='0') {
			if (cnt<n/2)
				ans[i]=')', ++cnt;
			else
				ans[i]='(';
		}
	cout << "! " << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 4 ms 592 KB Output is correct
3 Correct 8 ms 592 KB Output is correct
4 Correct 9 ms 592 KB Output is correct
5 Correct 8 ms 592 KB Output is correct
6 Correct 10 ms 592 KB Output is correct
7 Correct 8 ms 592 KB Output is correct
8 Correct 7 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 592 KB Output is correct
2 Correct 11 ms 592 KB Output is correct
3 Correct 8 ms 592 KB Output is correct
4 Correct 9 ms 592 KB Output is correct
5 Correct 8 ms 592 KB Output is correct
6 Correct 10 ms 592 KB Output is correct
7 Correct 7 ms 592 KB Output is correct
8 Correct 9 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 387 ms 792 KB Output is correct
3 Correct 912 ms 788 KB Output is correct
4 Correct 809 ms 800 KB Output is correct
5 Correct 698 ms 788 KB Output is correct
6 Correct 485 ms 788 KB Output is correct
7 Correct 707 ms 796 KB Output is correct
8 Correct 897 ms 792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 886 ms 792 KB Output is correct
3 Correct 699 ms 784 KB Output is correct
4 Correct 666 ms 788 KB Output is correct
5 Correct 482 ms 788 KB Output is correct
6 Correct 555 ms 788 KB Output is correct
7 Correct 583 ms 792 KB Output is correct
8 Correct 495 ms 792 KB Output is correct