#include <bits/stdc++.h>
using namespace std;
bool ask (int a, int b) {
cout << "? " << a << " " << b << endl;
int ans;
cin >> ans;
return ans;
}
int main () {
int n, Q;
cin >> n >> Q;
vector <int> unpaired (1, 1);
vector <char> sol (n + 1);
for (int i = 2; i <= n; i++) {
if (ask (unpaired.back (), i)) {
sol[unpaired.back ()] = '(';
sol[i] = ')';
unpaired.pop_back ();
}
else {
unpaired.push_back (i);
}
}
int sz = unpaired.size ();
for (int i = 0; i < sz / 2; i++)
sol[unpaired[i]] = '(';
for (int i = sz / 2 + 1; i < sz; i++)
sol[unpaired[i]] = ')';
cout << "! ";
for (int i = 1; i <= n; i++)
cout << sol[i];
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Integer parameter [name=l] equals to 0, violates the range [1, 1000] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Runtime error |
1 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |