QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395408#8239. Mysterious TreeQian#TL 0ms0kbC++14855b2024-04-21 14:16:232024-04-21 14:16:24

Judging History

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

  • [2024-04-21 14:16:24]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-04-21 14:16:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
int n;
bool ask(int x,int y){
	printf("? %d %d\n",x+1,y+1);
	fflush(stdout);
	int p;
	scanf("%d",&p);
	fflush(stdout);
	return p;
}
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int n;scanf("%d",&n);
		fflush(stdout);
		bool flag=0;
		for(int i=0;i<n;i+=2)
		  if(ask(i,i+1)){
		  	flag=1;
		  	if(ask(i,(i+2)%n)){
		  		if(ask(i,(i+3)%n)){
		  			printf("! 2\n");
				  }
				else printf("! 1\n"); 
			}
			else if(ask(i+1,(i+2)%n)){
		  		if(ask(i+1,(i+3)%n)){
		  			printf("! 2\n");
				  }
				else printf("! 1\n"); 
			}
			else printf("! 1\n");
			break;
		  }
		if(flag)continue;
		if(n&1){
			if(ask(n,1)){
				if(ask(n,2)){
					printf("! 2\n");
				}
				else printf("! 1\n");
			}
			else printf("! 1\n");
		}
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
4
1
0
1
0

output:

? 1 2
? 1 3
? 2 3
? 2 4

result: