#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define fr first
#define sc second
#define query(l, r) cout << "? " << l << " " << r << endl; cin >> res;
using namespace std;
const int N = 1e5 + 5;
string ans;
bool res;
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
int n, q;
cin >> n >> q;
ans.assign(n, ' ');
stack<int> s;
s.push(1);
int cnt = 0;
for (int i = 2; i <= n; i++) {
if (s.empty()) {
s.push(i);
continue;
}
int cur = s.top();
query(cur, i);
if (res) {
ans[cur - 1] = '(';
ans[i - 1] = ')';
cnt++;
s.pop();
} else
s.push(i);
}
int cntfrr = n / 2 - cnt;
for (int i = 0; i < n; i++) {
if (ans[i] == ' ') {
if (cntfrr) {
ans[i] = ')';
cntfrr--;
} else
ans[i] = '(';
}
}
cout << "! " << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
5 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
208 KB |
Output is correct |
6 |
Correct |
10 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
312 KB |
Output is correct |
3 |
Correct |
4 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
256 KB |
Output is correct |
5 |
Correct |
9 ms |
208 KB |
Output is correct |
6 |
Correct |
9 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
208 KB |
Output is correct |
8 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
381 ms |
396 KB |
Output is correct |
3 |
Correct |
522 ms |
392 KB |
Output is correct |
4 |
Correct |
455 ms |
400 KB |
Output is correct |
5 |
Correct |
679 ms |
396 KB |
Output is correct |
6 |
Correct |
516 ms |
396 KB |
Output is correct |
7 |
Correct |
566 ms |
804 KB |
Output is correct |
8 |
Correct |
665 ms |
392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
529 ms |
1328 KB |
Output is correct |
3 |
Correct |
684 ms |
784 KB |
Output is correct |
4 |
Correct |
622 ms |
864 KB |
Output is correct |
5 |
Correct |
550 ms |
540 KB |
Output is correct |
6 |
Correct |
551 ms |
876 KB |
Output is correct |
7 |
Correct |
610 ms |
664 KB |
Output is correct |
8 |
Correct |
776 ms |
396 KB |
Output is correct |