QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630498 | #8239. Mysterious Tree | zyq_313# | WA | 0ms | 3636kb | C++14 | 4.2kb | 2024-10-11 18:52:05 | 2024-10-11 18:53:25 |
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 g[7][7];
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;
// g[1][2] = g[2][1] = g[3][4] = g[4][3] = g[2][3] = g[3][2] = 1;
// g[1][3] = g[2][3] = g[4][3] = g[3][4] = g[3][2] = g[3][1] = 1;
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(1, o1);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}else if (r1 == 1){
int r2 = ask(1, 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: 0ms
memory: 3636kb
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)