#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] = ')';
int values = -1;
set<int>::iterator ptr;
if(crr != pos.begin()) {
ptr = crr;
ptr --;
values = *ptr;
} else {
if(it != (--pos.end())) {
ptr = it;
ptr ++;
values = *ptr;
}
}
pos.erase(crr);
pos.erase(it);
if(values != -1) {
it = pos.find(values);
}
}
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 |
Correct |
8 ms |
328 KB |
Output is correct |
3 |
Correct |
9 ms |
328 KB |
Output is correct |
4 |
Correct |
10 ms |
328 KB |
Output is correct |
5 |
Correct |
14 ms |
328 KB |
Output is correct |
6 |
Correct |
13 ms |
328 KB |
Output is correct |
7 |
Correct |
8 ms |
328 KB |
Output is correct |
8 |
Correct |
14 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
252 KB |
Output is correct |
2 |
Correct |
515 ms |
5104 KB |
Output is correct |
3 |
Correct |
847 ms |
5172 KB |
Output is correct |
4 |
Correct |
1214 ms |
5312 KB |
Output is correct |
5 |
Correct |
1000 ms |
5176 KB |
Output is correct |
6 |
Correct |
1080 ms |
5396 KB |
Output is correct |
7 |
Correct |
1034 ms |
5148 KB |
Output is correct |
8 |
Correct |
797 ms |
5180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
200 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |