#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
vector<int> v;
int ans[100005];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, q, cnt = 0;
cin >> n >> q;
v.push_back(1);
for (int i = 2; i <= n; i++) {
if (v.empty()) {
v.push_back(i);
continue;
}
int id = v.back();
cout << "? " << id << " " << i << endl;
bool in;
cin >> in;
if (in) cnt++, ans[id] = 1, ans[i] = 2, v.pop_back();
else v.push_back(i);
}
cnt = n / 2 - cnt;
cout << "! ";
for (int i = 1; i <= n; i++) {
if (ans[i] == 1) cout << '(';
else if (ans[i] == 2) cout << ')';
else if (cnt > 0) {
cout << ')';
cnt--;
}
else cout << '(';
}
cout << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
10 ms |
328 KB |
Output is correct |
4 |
Correct |
10 ms |
208 KB |
Output is correct |
5 |
Correct |
6 ms |
324 KB |
Output is correct |
6 |
Correct |
11 ms |
320 KB |
Output is correct |
7 |
Correct |
9 ms |
332 KB |
Output is correct |
8 |
Correct |
6 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
8 ms |
324 KB |
Output is correct |
6 |
Correct |
10 ms |
208 KB |
Output is correct |
7 |
Correct |
7 ms |
260 KB |
Output is correct |
8 |
Correct |
6 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
322 ms |
840 KB |
Output is correct |
3 |
Correct |
715 ms |
716 KB |
Output is correct |
4 |
Correct |
746 ms |
680 KB |
Output is correct |
5 |
Correct |
740 ms |
688 KB |
Output is correct |
6 |
Correct |
634 ms |
628 KB |
Output is correct |
7 |
Correct |
548 ms |
1004 KB |
Output is correct |
8 |
Correct |
642 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
628 ms |
940 KB |
Output is correct |
3 |
Correct |
675 ms |
908 KB |
Output is correct |
4 |
Correct |
816 ms |
1032 KB |
Output is correct |
5 |
Correct |
728 ms |
1012 KB |
Output is correct |
6 |
Correct |
645 ms |
1100 KB |
Output is correct |
7 |
Correct |
579 ms |
896 KB |
Output is correct |
8 |
Correct |
636 ms |
744 KB |
Output is correct |