QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#630436 | #8239. Mysterious Tree | zyq_313# | WA | 1ms | 3632kb | C++14 | 4.0kb | 2024-10-11 18:32:44 | 2024-10-11 18:32:45 |
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, o1), r1 = ask(o1 - 2, o2);
if (r == 0 && r1 == 0){
cout << "! 1" << endl;
}else if (r == 1){
int r2 = ask(o1 - 1, o1);
if (r2 != 1){
cout << "! 1" << endl;
}else{
cout << "! 2" << endl;
}
}else if (r1 == 1){
int r2 = ask(o1 - 1, 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();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3632kb
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)