QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#551945 | #8239. Mysterious Tree | Ashbourne# | WA | 1ms | 3816kb | C++23 | 2.1kb | 2024-09-07 19:16:38 | 2024-09-07 19:16:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n, m;
void solve(){
cin >> n;
if(n == 4){
int sum = 0, pos;
for(int i = 2; i <= 4; ++ i){
cout << "? " << 1 << " " << i << endl;
int s; cin >> s;
sum += s;
if(s) pos = i;
}
if(sum == 3) cout << "! 2" << endl;
else
if(sum == 2)cout << "! 1" << endl;
else{
sum = 0;
for(int i = 2; i <= 4; ++ i){
if(i == pos) continue;
cout << "? " << pos << " " << i << endl;
int s; cin >> s;
sum += s;
}
if(sum == 2) cout << "! 2" << endl;
if(sum == 1) cout << "! 1" << endl;
}
return;
}
bool flag = 0;
int x, y;
for(int i = 1; i <= n - 1; i += 2){
cout << "? " << i << " " << i + 1 << endl;
int s; cin >> s;
if(s){
flag = 1;
x = i; y = i + 1;
break;
}
}
if((n & 1) && !flag){
cout << "? " << n - 1 << " " << n << endl;
int s; cin >> s;
if(s){
flag = 1;
x = n - 1; y = n;
}
}
if(!flag){
cout << "! 1" << endl;
}else{
vector<int> dat(4);
int s = 0;
for(int i = 1; i <= n; ++ i){
if(i != x && i != y) dat[++s] = i;
if(s == 3) break;
}
int sum = 0;
cout << "? " << x << " " << dat[1] << endl;
int s1 = 0;
cin >> s1;
sum += s1;
cout << "? " << y << " " << dat[2] << endl;
int s2 = 0;
cin >> s2;
sum += s2;
if(sum == 0 || sum == 2) {
cout << "! 1" << endl;
}else{
int pos;
if(s1) pos = x; else pos = y;
cout << "? " << pos << " " << dat[3] << endl;
int s3; cin >> s3;
if(s3) cout << "! 1" << endl;
else cout << "! 2" << endl;
}
}
}
int main(){
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3816kb
input:
2 4 1 0 0 1 0 4 0 1 0 1 1
output:
? 1 2 ? 1 3 ? 1 4 ? 2 3 ? 2 4 ! 1 ? 1 2 ? 1 3 ? 1 4 ? 3 2 ? 3 4 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3616kb
input:
87 13 0 0 0 0 0 1 0 1 1
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 1 ? 12 2 ? 12 3 ! 1
result:
wrong answer Wrong prediction (test case 1)