Submission #865812

# Submission time Handle Problem Language Result Execution time Memory
865812 2023-10-24T17:45:14 Z serifefedartar Zagrade (COI20_zagrade) C++17
71 / 100
527 ms 2112 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20; 
const ll MAXN = 3e5 + 100;

int ask(int l, int r) {
	cout << "? " << l << " " << r << endl;
	cout.flush();
	int x; cin >> x;
	return x;
}

void answer(string s) {
	cout << "! " << s << endl;
	cout.flush();
	exit(0);
}

int main() {
	fast
	int N, Q;
	cin >> N >> Q;

	stack<int> st;
	string ans;
	for (int i = 1; i <= N; i++) {
		if (st.empty()) {
			st.push(i);
			ans += '(';
		} else {
			int x = ask(st.top(), i);
			if (x) {
				st.pop();
				ans += ')';
			} else {
				st.push(i);
				ans += '(';
			}
		}
	}

	int n = st.size();
	answer(ans);
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:48:6: warning: unused variable 'n' [-Wunused-variable]
   48 |  int n = st.size();
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 4 ms 600 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 241 ms 1512 KB Output is correct
3 Correct 465 ms 1456 KB Output is correct
4 Correct 527 ms 1552 KB Output is correct
5 Correct 486 ms 1556 KB Output is correct
6 Correct 512 ms 2112 KB Output is correct
7 Correct 523 ms 1780 KB Output is correct
8 Correct 462 ms 1544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -