#include <bits/stdc++.h>
using namespace std;
int n, q;
inline bool query(int l, int r) {
cout << "? " << l << ' ' << r << endl;
bool res;
cin >> res;
return res;
}
int main() {
cin >> n >> q;
set<int> pos;
for(int i = 1;i <= n;i ++) {
pos.insert(i);
}
char ans[n+1];
ans[n] = '\0';
auto it = pos.begin();
while(it != (--pos.end())) {
auto crr = (it++);
if(query(*crr, *it)) {
ans[(*crr) - 1] = '(';
ans[(*it) - 1] = ')';
pos.erase(it);
it = (crr--);
pos.erase(it);
it = crr;
}
if((int)pos.size() == 0) {
break;
}
}
if((int)pos.size()) {
it = pos.begin();
for(int rep = 0;rep < (int)pos.size() / 2;rep ++) {
ans[(*it)-1] = ')';
}
while(it != pos.end()) {
ans[(*it)-1] = '(';
}
}
string out = ans;
cout << "! " << out << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Execution timed out |
3072 ms |
328 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3069 ms |
200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Execution timed out |
3077 ms |
4928 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3053 ms |
200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |