#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
cin.tie(0); ios_base::sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector<int> ans(n, -1);
set<int> s;
s.insert(0);
for(int i = 1; i < n; i++) {
if(ans[i] != -1) continue;
// cout << "Masuk " << i << '\n';
while(!s.empty()) {
int l = *s.rbegin(), r = i;
if(l >= 0 && r < n) {
cout << "? " << l + 1 << " " << r + 1 << endl;
int x; cin >> x;
if(x) {
ans[l] = 1;
ans[r] = 0;
s.erase(l);
i++;
} else {
s.insert(r);
break;
}
} else {
break;
}
}
if(s.empty() && ans[i] == -1) s.insert(i);
}
for(int i = 0; i < n; i++) {
int j = i;
while(j < n && ans[j] == -1) j++;
int l = (i + j) / 2 - 1, r = (i + j) / 2;
while(l >= 0 && ans[l] == -1) {
ans[l] = 0, ans[r] = 1;
l--, r++;
}
}
cout << "! ";
for(int i = 0; i < n; i++) {
assert(ans[i] != -1);
if(ans[i]) cout << '(';
else cout << ')';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
208 KB |
Output is correct |
4 |
Correct |
10 ms |
208 KB |
Output is correct |
5 |
Correct |
10 ms |
208 KB |
Output is correct |
6 |
Correct |
9 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
336 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
8 ms |
352 KB |
Output is correct |
3 |
Incorrect |
8 ms |
208 KB |
Mismatch at position 6. Expected ), found ( |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
409 ms |
720 KB |
Output is correct |
3 |
Correct |
863 ms |
696 KB |
Output is correct |
4 |
Correct |
531 ms |
700 KB |
Output is correct |
5 |
Correct |
793 ms |
720 KB |
Output is correct |
6 |
Correct |
869 ms |
720 KB |
Output is correct |
7 |
Correct |
881 ms |
3152 KB |
Output is correct |
8 |
Correct |
736 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
845 ms |
5484 KB |
Output is correct |
3 |
Incorrect |
806 ms |
1676 KB |
Mismatch at position 22. Expected ), found ( |
4 |
Halted |
0 ms |
0 KB |
- |