QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#712079#8239. Mysterious TreeKafuuChinocpp#WA 1ms3828kbC++141.3kb2024-11-05 14:29:292024-11-05 14:29:37

Judging History

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

  • [2024-11-05 14:29:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-11-05 14:29:29]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int N=3e5+10;
int T,n; 

void solve(){
	cin>>n;
	int flag=0;
	for(int i=1;i<=n;i+=2){
		if(i!=n) printf("? %d %d\n",i,i+1), fflush(stdout);
		else printf("? %d %d\n",i,i-1), fflush(stdout);
		int ans;
		cin>>ans;
		if(ans){
			int res[2]={0}, cnt=0;
			for(int j=1;j<=n;j++){
				if((i!=n&&j!=i&&j!=i+1)||(i==n&&j!=i&&j!=i-1)){
					printf("? %d %d\n",i,j); fflush(stdout);
					cin>>res[cnt++];
					if(!res[cnt]) break;
				}
				if(cnt==2){
					if(res[0]&&res[1]) printf("! 2\n"), fflush(stdout);
					else printf("! 1\n"), fflush(stdout);
					flag=1;
					break;
				}
			}
			if(flag) break;
			res[0]=res[1]=0; cnt=0;
			for(int j=1;j<=n;j++){
				if(i!=n&&j!=i&&j!=i+1){
					printf("? %d %d\n",i+1,j); fflush(stdout);
					cin>>res[cnt++];
				}
				else if(i==n&&j!=i&&j!=i-1){
					printf("? %d %d\n",i-1,j); fflush(stdout);
					cin>>res[cnt++];
				}
				if(cnt==2){
					if(res[0]&&res[1]) printf("! 2\n"), fflush(stdout);
					else printf("! 1\n"), fflush(stdout);
					flag=1;
					break;
				}	
			}
		}
	}
	if(!flag) printf("! 1\n"),  fflush(stdout);
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>T;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1
0
1
0
4
1
1

output:

? 1 2
? 1 3
? 2 3
? 2 4
! 1
? 3 4
? 3 1
? 1 0

result:

wrong answer Integer 0 violates the range [1, 4] (test case 2)