#include<bits/stdc++.h>
using namespace std;
//cout.flush();
const int MAXN=100010;
int resp[MAXN];
int main(){
int n, q;
cin >> n >> q;
cout << "? 1 " << n << endl;
//std::cout << std::flush;
int ehVal;
cin >> ehVal;
if(ehVal){
resp[1] = 1;
int a = 1, f = 0;
stack <int> s;
s.push(1);
int l = 1;
for(int i=2; i<n; i++){
if(l==0){
a++;
resp[i] = 1;
s.push(i);
l = i;
continue;
}
cout << "? " << l << " " << i << endl;
//std::cout << std::flush;
int val;
cin >> val;
if(val){
f++;
resp[i] = 2;
s.pop();
if(s.empty()) l = 0;
else l = s.top();
}
else{
a++;
resp[i] = 1;
s.push(i);
l = i;
}
}
resp[n] = 2;
cout << "! ";
for(int i=1; i<=n; i++){
if(resp[i]==1) cout << "(";
else cout << ")";
}
return 0;
}
int a= 0, b = 0;
for(int i=1; i<=n; i++){
for(int j=i+1; j<=n; j++){
if((j-i)%2==0) continue;
cout << "? " << i << " " << j << endl;
int val;
cin >> val;
if(val){
resp[i] = 1;
resp[j] = 2;
a++; b++;
}
}
}
for(int i=1; i<=n; i++){
if(resp[i]==0){
if(b==n/2){
resp[i] = 1;
a++;
}
else{
resp[i] = 2;
b++;
}
}
}
cout << "! ";
for(int i=1; i<=n; i++){
if(resp[i]==1) cout << "(";
else cout << ")";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
440 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
444 KB |
Output is correct |
7 |
Correct |
5 ms |
600 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
295 ms |
1248 KB |
Output is correct |
3 |
Correct |
533 ms |
1144 KB |
Output is correct |
4 |
Correct |
566 ms |
1204 KB |
Output is correct |
5 |
Correct |
587 ms |
1524 KB |
Output is correct |
6 |
Correct |
558 ms |
1224 KB |
Output is correct |
7 |
Correct |
572 ms |
1316 KB |
Output is correct |
8 |
Correct |
563 ms |
948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
344 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |