#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
const int MAX = 1e5 + 10;
int n, q;
int x;
vector <int> v;
int arr[MAX];
int main() {
cin >> n >> q;
v.push_back(1);
for (int i = 2; i <= n; i++) {
if (v.size() == 0) {
v.push_back(i);
continue;
}
cout << "? " << v.back() << " " << i << endl;
cin >> x;
if (x == 0) {
v.push_back(i);
}
else {
arr[i] = 2;
arr[v.back()] = 1;
v.pop_back();
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (arr[i] == 0) {
cnt++;
}
}
cnt /= 2;
cout << "! ";
for (int i = 1; i <= n; i++) {
if (arr[i] == 1) {
cout << "(";
}
else if (arr[i] == 2) {
cout << ")";
}
else {
if (cnt) {
cout << ")";
cnt--;
}
else {
cout << "(";
}
}
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
8 ms |
200 KB |
Output is correct |
3 |
Correct |
13 ms |
200 KB |
Output is correct |
4 |
Correct |
9 ms |
200 KB |
Output is correct |
5 |
Correct |
12 ms |
200 KB |
Output is correct |
6 |
Correct |
10 ms |
296 KB |
Output is correct |
7 |
Correct |
12 ms |
292 KB |
Output is correct |
8 |
Correct |
12 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
12 ms |
200 KB |
Output is correct |
3 |
Correct |
15 ms |
200 KB |
Output is correct |
4 |
Correct |
9 ms |
200 KB |
Output is correct |
5 |
Correct |
8 ms |
200 KB |
Output is correct |
6 |
Correct |
9 ms |
200 KB |
Output is correct |
7 |
Correct |
12 ms |
304 KB |
Output is correct |
8 |
Correct |
11 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
388 ms |
672 KB |
Output is correct |
3 |
Correct |
784 ms |
840 KB |
Output is correct |
4 |
Correct |
1006 ms |
784 KB |
Output is correct |
5 |
Correct |
1022 ms |
764 KB |
Output is correct |
6 |
Correct |
710 ms |
724 KB |
Output is correct |
7 |
Correct |
718 ms |
940 KB |
Output is correct |
8 |
Correct |
965 ms |
868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
892 ms |
1008 KB |
Output is correct |
3 |
Correct |
863 ms |
964 KB |
Output is correct |
4 |
Correct |
761 ms |
1084 KB |
Output is correct |
5 |
Correct |
897 ms |
892 KB |
Output is correct |
6 |
Correct |
1119 ms |
976 KB |
Output is correct |
7 |
Correct |
923 ms |
916 KB |
Output is correct |
8 |
Correct |
879 ms |
668 KB |
Output is correct |