QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630449 | #8239. Mysterious Tree | zyq_313# | WA | 1ms | 3628kb | C++14 | 4.1kb | 2024-10-11 18:37:31 | 2024-10-11 18:37:32 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int N = 3e5 + 10;
using ll = long long;
int n;
int ask(int a, int b){
cout << "? " << a << ' ' << b << endl;
int ans;
cin >> ans;
return ans;
}
bool have_edge[510];
void solve(){
cin >> n;
int o1, o2;
int flag = 0;
if (n & 1){
for (int i = 1; i <= n / 2; i ++){
// have_edge[i] = ask(2 * i - 1, 2 * i);
int r = ask(2 * i - 1, 2 * i);
if (r){
o1 = 2 * i - 1, o2 = 2 * i;
flag = 1;
break;
}
}
if (!flag){
int r = ask(n, 1);
if (r){
o1 = n, o2 = 1;
flag = 1;
}
}
if (!flag){
cout << "! 1" << endl;
}
if (max(o1, o2) == n){
int r = ask(2, o1), r1 = ask(2, o2);
if (r == 0 && r1 == 0){
cout << "! 1" << endl;
}else if (r == 1){
int r2 = ask(3, o1);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}else if (r1 == 1){
int r2 = ask(3, o2);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}
}else{
int r = ask((o1 - 2 + n) % n + 1, o1), r1 = ask((o1 - 2 + n) % n + 1, o2);
if (r == 0 && r1 == 0){
cout << "! 1" << endl;
}else if (r == 1){
int r2 = ask((o1 - 1 + n) % n + 1, o1);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}else if (r1 == 1){
int r2 = ask((o1 - 1 + n) % n, o2);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}
}
}else{
for (int i = 1; i <= n / 2; i ++){
// have_edge[i] = ask(2 * i - 1, 2 * i);
int r = ask(2 * i - 1, 2 * i);
if (r){
o1 = 2 * i - 1, o2 = 2 * i;
flag = 1;
break;
}
}
if (!flag){
cout << "! 1" << endl;
}
if (max(o1, o2) == n){
int r = ask(2, o1), r1 = ask(2, o2);
if (r == 0 && r1 == 0){
cout << "! 1" << endl;
}else if (r == 1){
int r2 = ask(3, o1);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}else if (r1 == 1){
int r2 = ask(3, o2);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}
}else{
int r = ask((o1 - 2 + n) % n + 1, o1), r1 = ask((o1 - 2 + n) % n, o2);
if (r == 0 && r1 == 0){
cout << "! 1" << endl;
}else if (r == 1){
int r2 = ask((o1 - 1 + n) % n, o1);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}else if (r1 == 1){
int r2 = ask((o1 - 1 + n) % n, o2);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}
}
}
}
int main(){
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t --) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3628kb
input:
2 4 1 0 1
output:
? 1 2 ? 4 1 ? 3 2 ? 0 2
result:
wrong answer Integer 0 violates the range [1, 4] (test case 1)