#include <iostream>
#include <vector>
#include <stack>
#include <climits>
#include <algorithm>
using namespace std;
int n, q, emp;
stack<int> unpaired;
char s[100005];
string ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
unpaired.push(0);
for (int i = 1; i < n; i++) {
if (unpaired.empty()) {
unpaired.push(i);
continue;
}
cout << "? " << unpaired.top() << " " << i << "\n";
cout.flush();
int res; cin >> res;
if (res) {
s[unpaired.top()] = '(';
s[i] = ')';
unpaired.pop();
} else {
unpaired.push(i);
}
}
for (int i = 0; i < n; i++) {
if (!(s[i] == '(' || s[i] == ')')) emp++;
}
emp /= 2;
for (int i = 0; i < n; i++) {
if (s[i] == '(' || s[i] == ')') {
ans += s[i];
} else {
if (emp) {
ans += ')';
emp--;
} else {
ans += '(';
}
}
}
cout << "! " << ans << "\n";
cout.flush();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |