QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401801 | #8239. Mysterious Tree | younger | WA | 1ms | 3708kb | C++20 | 2.2kb | 2024-04-29 14:02:00 | 2024-04-29 14:02:01 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
int n;
bool ask(int a , int b)
{
cout << "? " << a << ' ' << b << endl;
bool res;
cin >> res;
return res;
}
void print(int x)
{
cout << "! " << x << endl;
return;
}
void Asuka()
{
cin >> n;
if(n & 1){
int pos = -1;
for(int i = 1 ; i < n ; i += 2){
if(ask(i , i + 1)){
pos = i;
break;
}
}
if(pos == -1){
if(ask(n , 1))pos = n;
}
if(pos == -1){
print(1);
return;
}
int cnt = 0 , num = 0;
for(int i = 1 ; i <= n ; i ++){
if(i == pos || i == pos % n + 1)continue;
if(ask(pos , i))cnt ++;
else break;
if(cnt == 2)break;
}
if(cnt == 2){
print(2);
return;
}else if(cnt == 1){
print(1);
return;
}
cnt = 0;
for(int i = 1 ; i <= n ; i ++){
if(i == pos || i == pos % n + 1)continue;
if(ask(pos % n + 1 , i))cnt ++;
else break;
if(cnt == 2)break;
}
if(cnt == 2){
print(2);
return;
}else {
print(1);
return;
}
}else{
int pos = -1;
for(int i = 1 ; i <= n ; i += 2){
if(ask(i , i + 1)){
pos = i;
break;
}
}
if(pos == -1){
print(1);
return;
}
int cnt = 0 , num = 0;
for(int i = 1 ; i <= n ; i ++){
if(i == pos || i == pos % n + 1)continue;
if(ask(pos , i))cnt ++;
else break;
if(cnt == 2)break;
}
if(cnt == 2){
print(2);
return;
}else if(cnt == 1){
print(1);
return;
}
cnt = 0;
for(int i = 1 ; i <= n ; i ++){
if(i == pos || i == pos % n + 1)continue;
if(ask(pos % n + 1 , i))cnt ++;
else break;
if(cnt == 2)break;
}
if(cnt == 2){
print(2);
return;
}else {
print(1);
return;
}
}
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t --){
Asuka();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3708kb
input:
2 4 1 4
output:
? 1 2 ! 1
result:
wrong answer format Unexpected end of file - token expected (test case 2)