QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401801#8239. Mysterious TreeyoungerWA 1ms3708kbC++202.2kb2024-04-29 14:02:002024-04-29 14:02:01

Judging History

你现在查看的是最新测评结果

  • [2024-04-29 14:02:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3708kb
  • [2024-04-29 14:02:00]
  • 提交

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;
}

详细

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)