QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#450571#8239. Mysterious Treeliqingyang#WA 1ms3588kbC++17743b2024-06-22 15:47:432024-06-22 15:47:43

Judging History

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

  • [2024-06-22 15:47:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3588kb
  • [2024-06-22 15:47:43]
  • 提交

answer

#include<iostream>
using namespace std;
int T,n,ans=0;
inline bool query(int x,int y)
{
	cout<<"? "<<x<<" "<<y<<endl;
	bool z;
	cin>>z;
	return z;
}
inline void judge(int x,int y)
{
	if(ans||!x)
	{
		return;
	}
	int cnt=bool(y);
	for(int i=1;cnt<2&&i<=n;i++)
	{
		if(i==x||i==y)
		{
			continue;
		}
		if(!query(x,i))
		{
			if(cnt>=2)
			{
				ans=1;
			}
			return;
		}
		cnt++;
	}
	ans=2;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;
		int p=0,q=0;
		for(int i=1;i<n;i+=2)
		{
			if(query(i,i+1))
			{
				p=i,q=i+1;
				break;
			}
		}
		p=(!p&&(n&1))?n:p;
		ans=0,judge(p,q),judge(q,p);
		cout<<"! "<<max(1,ans)<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3588kb

input:

2
4
1
0
1

output:

? 1 2
? 1 3
? 2 3
! 2

result:

wrong answer Wrong prediction (test case 1)