QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356013#8239. Mysterious TreeUSTC_fish_touching_team#WA 0ms1612kbC++141.1kb2024-03-17 14:43:392024-03-17 14:43:40

Judging History

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

  • [2024-03-17 14:43:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1612kb
  • [2024-03-17 14:43:39]
  • 提交

answer

#include<cstdio>
using namespace std;
int T,n;
int query(int u,int v){
	printf("? %d %d\n",u,v);
	fflush(stdout);
	int res=0;
	scanf("%d",&res);
	return res;
}
void get(int u){
	printf("! %d\n",u);
	fflush(stdout);
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		int cnt=0,pos;
		for(int i=1;i<=n;i+=2){
			int res=query(i,i+1);
			if(res){
				cnt++;
				pos=i;
			}
		}
		if(cnt>=2){
			get(1);
			continue;
		}
		
		int a,b,x,y;
		if(n%2==1){
			int res=query(n-1,n);
			if(res){
				if(cnt==1&&pos<n-2){
					get(1);
					continue;
				}else{
					a=n-1,b=n;
				}
			}else{
				if(cnt==0){
					get(1);
					continue;
				}else{
					a=pos;b=pos+1;
				}
			}
		}else{
			if(cnt==0){
				get(1);
				continue;
			}else{
				a=pos,b=pos+1;
			}
		}
		
		if(a==1)x=3,y=4;
		else x=1,y=2;
		
		int ra=query(a,x);
		int rb=query(b,x);
		
		if(ra==0&&rb==0){
			get(1);
			continue;
		}
		
		if(rb==0){
			if(query(a,y))get(2);
			else get(1);
		}else{
//			assert(ra==0);
			if(query(b,y))get(2);
			else get(1);
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 1612kb

input:

2
4
1
1
4
0
1
1
0
1

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 1604kb

input:

87
13
0
0
0
0
0
1

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14

result:

wrong answer Integer 14 violates the range [1, 13] (test case 1)