Submission #581624

# Submission time Handle Problem Language Result Execution time Memory
581624 2022-06-22T22:46:10 Z penguinhacker Zagrade (COI20_zagrade) C++17
0 / 100
817 ms 840 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];
			}
			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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Incorrect 10 ms 592 KB Mismatch at position 1. Expected (, found )
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 8 ms 644 KB Output is correct
3 Incorrect 12 ms 592 KB Mismatch at position 306. Expected (, found )
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 213 ms 792 KB Output is correct
3 Incorrect 817 ms 840 KB Mismatch at position 1. Expected (, found )
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 590 ms 788 KB Output is correct
3 Incorrect 636 ms 784 KB Mismatch at position 255. Expected (, found )
4 Halted 0 ms 0 KB -