Submission #928628

# Submission time Handle Problem Language Result Execution time Memory
928628 2024-02-16T20:44:32 Z NK_ Zagrade (COI20_zagrade) C++17
100 / 100
477 ms 1768 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define sz(x) int(x.size())

template<class T> using V = vector<T>;
using vi = V<int>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, Q; cin >> N >> Q;

	auto qry = [&](int l, int r) {
		cout << "? " << l + 1 << " " << r + 1 << endl;
		int res; cin >> res;
		return res;
	};

	vi stk = {0};
	string ans(N, '?');
	for(int i = 1; i < N; i++) {
		if (qry(stk.back(), i)) {
			ans[stk.back()] = '(';
			ans[i] = ')';
			stk.pop_back();
		} else stk.push_back(i);
	}

	int M = sz(stk) / 2;
	for(int i = 0; i < M; i++) {
		ans[stk[i]] = ')';
		ans[stk[i + M]] = '(';
	}	

	cout << "! " << ans << endl;

	exit(0-0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 4 ms 856 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 420 ms 520 KB Output is correct
3 Correct 428 ms 596 KB Output is correct
4 Correct 468 ms 600 KB Output is correct
5 Correct 451 ms 528 KB Output is correct
6 Correct 477 ms 528 KB Output is correct
7 Correct 418 ms 1768 KB Output is correct
8 Correct 471 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 440 ms 1516 KB Output is correct
3 Correct 427 ms 792 KB Output is correct
4 Correct 476 ms 1048 KB Output is correct
5 Correct 426 ms 988 KB Output is correct
6 Correct 414 ms 1360 KB Output is correct
7 Correct 433 ms 1276 KB Output is correct
8 Correct 434 ms 528 KB Output is correct