QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882013#9734. Identify ChordlichenghanWA 26ms3712kbC++173.2kb2025-02-04 20:36:322025-02-04 20:36:33

Judging History

This is the latest submission verdict.

  • [2025-02-04 20:36:33]
  • Judged
  • Verdict: WA
  • Time: 26ms
  • Memory: 3712kb
  • [2025-02-04 20:36:32]
  • Submitted

answer

#include <bits/stdc++.h>
//#define SELF
//#define SELFGEN
using namespace std;
int n;
inline int dist(int x,int y){
	if(x>y) swap(x,y);
	return min(y-x,n-y+x);
}
#ifdef SELF
int hida,hidb;
int cntask;
int ask(int x,int y){
	++cntask;
	printf("? %d %d ",x,y);
	int ans=min({dist(x,y),dist(x,hida)+1+dist(hidb,y),dist(x,hidb)+1+dist(hida,y)});
	printf("= %d\n",ans);
	return ans;
}
void answer(int x,int y){
	printf("! %d %d = ",x,y);
	if(x==hida&&y==hidb||x==hidb&&y==hida){
		printf("CORRECT, cnt=%d\n\n",cntask);
	}else{
		printf("WRONG (%d %d %d)\n",n,hida,hidb);
		exit(0);
	}
}
#else
int ask(int x,int y){
	++x; ++y;
	printf("? %d %d\n",x,y); fflush(stdout);
	int ans;
	scanf("%d",&ans);
	return ans;
}
void answer(int x,int y){
	++x; ++y;
	printf("! %d %d\n",x,y); fflush(stdout);
	int ans;
	scanf("%d",&ans);
	if(ans==-1) exit(0);
}
#endif

int qmid(int x){
	if(n&1){
		int y=(x+n/2)%n,z=(x+n-n/2)%n;
		return 2*min(ask(x,y),ask(x,z))+1;
	}else{
		return 2*ask(x,(x+n/2)%n);
	}
}
struct RND{
	mt19937 e;
	RND():e(chrono::steady_clock::now().time_since_epoch().count()){};
	int operator()(int x,int y){ return e()%(y-x+1)+x;}
};
#undef assert
#ifdef SELF
#define assert(x)\
	{if(!(x)){printf("ERROR: Assert failed (%d %d %d)\n",n,hida,hidb); puts(#x); }}
#else
#define assert(x) ((void)0)
#endif
void solve(){
#ifdef SELFGEN
	RND rnd;
	n=rnd(4,1000);
	hida=rnd(0,n-1);
	do hidb=rnd(0,n-1); while(dist(hida,hidb)<=1);
	cntask=0;
#else
	scanf("%d",&n);
#ifdef SELF
	scanf("%d%d",&hida,&hidb);
	cntask=0;
#endif
#endif
	if(n<=10){
		for(int i=0;i<n;i++){
			for(int j=i+2;j<n;j++){
				if(i==0&&j==n-1) continue;
				if(ask(i,j)==1) {
					answer(i,j);
					return;
				}
			}
		}
	}
	int x=0,y=n/3,z=2*n/3;
	int dx=qmid(x),dy=qmid(y),dz=qmid(z);
	if(dx==dy&&dy==dz){
		int dans=(n-dx)/2+1;
		int dxy=ask(x,y),dyz=ask(y,z),dzx=ask(z,x);
		if(dyz==dist(y,z)-dans+1){
			x=y; y=z;
		}else if(dzx==dist(z,x)-dans+1){
			y=x; x=z;
		}else assert(dxy==dist(x,y)-dans+1);
		int l=dans,r=dist(y,x),mid,drit=-1;
		while(l<=r){
			mid=(l+r)>>1;
			int w=(x+mid)%n;
			if(ask(x,w)==dist(x,w)-dans+1){
				drit=mid;
				r=mid-1;
			}else{
				l=mid+1;
			}
		}
		assert(drit!=-1);
		x+=drit;
		answer(x,(x-dans+n)%n);
		return;
	}else{
		if(dy>dx) swap(x,y),swap(dx,dy);
		if(dz>dx) swap(x,z),swap(dx,dz);
		int dxm=(n-dx)/4+1;
		int u=-1,v;
		for(int i:{dxm,n-dxm,dxm-1,dxm+1,n-dxm-1,n-dxm+1}){
			if(qmid((x+i)%n)==n){
				u=(x+i)%n; break;
			}
		}
		assert(u!=-1);
		v=u;
		while(qmid((u+n-1)%n)==n) u=(u+n-1)%n;
		while(qmid((v+1)%n)==n) v=(v+1)%n;
//		printf("%d %d\n",u,v);
		assert(v==(u+1)%n||v==u);
		int p=u+n/4;
		int dans=0;
		for(int i=p-2;i<=p+2;i++) dans=max(dans,(n-qmid(i%n))/2);
		int dma=(dans+1)/2;
		for(int d:{dma,n/2-dma,dma-1,dma+1,n/2-dma-1,n/2-dma+1}){
			int uu=(u-d+n)%n,vv=(v+d)%n;
			if(dist(uu,vv)!=1&&ask(uu,vv)==1) {
				answer(uu,vv);
				return;
			}
		}
#ifdef SELF
		printf("ERROR: ANSWER NOT FOUND (%d %d %d)\n",n,hida,hidb);
#endif
		exit(0);
	}
}

int main(){
	int tc;
	scanf("%d",&tc);
	while(tc--){
		solve();
	}
}
/*
2
1000000000 160000000 170000000
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

2
6
2
2
2
1
1
4
1
1

output:

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

result:

ok ok (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 26ms
memory: 3712kb

input:

1000
15
6
5
7
7
5
6
7
7
7
7
6
5
5
6
7
7
5
6
5
6
5
6
5
6
1
1
19
4
5
9
9
3
2
9
9
9
9
8
7
7
8
7
8
5
6
3
4
1
2
3
2
1
1
17
4
5
8
7
3
2
8
8
8
7
7
8
5
6
3
4
1
2
3
2
5
4
1
1
15
7
6
6
7
7
6
4
5
5
2
1
1
14
5
5
7
7
7
5
5
7
5
5
5
5
3
5
1
1
15
2
3
7
7
5
4
5
6
7
7
6
5
7
7
5
6
7
7
5
6
3
4
1
2
3
2
1
1
17
8
8
3
2
4
...

output:

? 1 9
? 1 8
? 6 14
? 6 13
? 11 4
? 11 3
? 7 15
? 7 14
? 6 14
? 6 13
? 5 13
? 5 12
? 8 1
? 8 15
? 7 15
? 7 14
? 8 1
? 8 15
? 9 2
? 9 1
? 10 3
? 10 2
? 11 4
? 11 3
? 5 8
! 5 8
? 1 11
? 1 10
? 7 17
? 7 16
? 13 4
? 13 3
? 8 18
? 8 17
? 7 17
? 7 16
? 6 16
? 6 15
? 9 19
? 9 18
? 9 19
? 9 18
? 10 1
? 10 19...

result:

wrong answer Integer 21 violates the range [1, 20] (test case 48)