# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706365 | vjudge1 | Zagrade (COI20_zagrade) | C++17 | 854 ms | 1420 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define endl '\n'
const int M = 4e5+5, MOD = 998244353;
char s[M];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, q;
cin >> n >> q;
int cnt = n/2;
stack<int> st;
for (int i = 1; i <= n; i++) {
if (!st.size()) st.push(i);
else {
cout << "? " << st.top() << ' ' << i << endl;
int x;
cin >> x;
if (x) cnt--, s[i]=')', s[st.top()] = '(', st.pop();
else st.push(i);
}
}
cout << "! ";
for (int i = 1; i <= n; i++)
if (!s[i]) cnt?s[i]=')', cnt--:s[i]='(';
for (int i = 1; i <= n; i++) cout << s[i]; cout << endl;
return 0;
}
/*
1234567890123456
))(()(())()(()()
)))()(())())()()
16 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 1
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |