#include <bits/stdc++.h>
using namespace std;
#define sp " "
//#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 200005
int ask(int a, int b){
cout<<"? "<<a<<sp<<b<<endl;
int res;
cin>>res;
return res;
}
int32_t main(){
//fileio();
//fastio();
int n, q;
cin>>n>>q;
vector<int> arr;
map<int ,int> pos;
int curr = 0, it = 1;
while(it < n){
int res = ask(it, it + 1);
if (res == 1) arr.pb(1), arr.pb(-1), pos[1] = it, pos[0] = it + 1;
else arr.pb(1), arr.pb(1), curr = 2, pos[1] = it, pos[2] = it + 1;
for (it += 2; it <= n; it++){
if (curr == 0) break;
int to = pos[curr - 1] + 1;
int res = ask(to, it);
if (res == 1){
curr -= 1;
arr.pb(-1);
}
else{
curr += 1;
arr.pb(1);
}
pos[curr] = it;
}
}
cout<<"! ";
for (auto i : arr){
cout<<((i == 1) ? '(' : ')');
}
cout<<endl;
//cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
300 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
9 ms |
208 KB |
Output is correct |
6 |
Correct |
9 ms |
300 KB |
Output is correct |
7 |
Correct |
9 ms |
328 KB |
Output is correct |
8 |
Correct |
7 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
374 ms |
936 KB |
Output is correct |
3 |
Correct |
630 ms |
868 KB |
Output is correct |
4 |
Correct |
675 ms |
912 KB |
Output is correct |
5 |
Correct |
596 ms |
840 KB |
Output is correct |
6 |
Correct |
662 ms |
984 KB |
Output is correct |
7 |
Correct |
630 ms |
3136 KB |
Output is correct |
8 |
Correct |
737 ms |
936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Mismatch at position 1. Expected ), found ( |
2 |
Halted |
0 ms |
0 KB |
- |