#include <bits/stdc++.h>
using namespace std;
bool query(const int &i, const int &j) {
cout << "? " << i + 1 << ' ' << j + 1 << endl;
bool ans;
cin >> ans;
return ans;
}
int main() {
int N, Q;
cin >> N >> Q;
string sol;
sol.resize(N);
stack<int> S;
for(int i = 0; i < N; ++i) {
if(S.empty()) {
S.emplace(i);
sol[i] = '(';
continue;
}
bool ans = query(S.top(), i);
if(ans) {
sol[i] = ')';
S.pop();
}
else {
sol[i] = '(';
S.emplace(i);
}
}
cout << "! " << sol << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
8 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
364 KB |
Output is correct |
6 |
Correct |
9 ms |
364 KB |
Output is correct |
7 |
Correct |
10 ms |
364 KB |
Output is correct |
8 |
Correct |
10 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
423 ms |
492 KB |
Output is correct |
3 |
Correct |
943 ms |
476 KB |
Output is correct |
4 |
Correct |
953 ms |
476 KB |
Output is correct |
5 |
Correct |
770 ms |
476 KB |
Output is correct |
6 |
Correct |
963 ms |
492 KB |
Output is correct |
7 |
Correct |
743 ms |
800 KB |
Output is correct |
8 |
Correct |
999 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |