QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#715118#9537. Chinese Chessas_lyrTL 952ms4252kbC++142.9kb2024-11-06 10:30:362024-11-06 10:30:36

Judging History

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

  • [2024-11-06 10:30:36]
  • 评测
  • 测评结果:TL
  • 用时:952ms
  • 内存:4252kb
  • [2024-11-06 10:30:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=540,M=10,V=20,B=6,n=9,m=8;
char s[B]={'J','S','C','M','X','B'};
bitset <N> bt[B];
bitset <N> bs[M][M][V];
int dis[N][N];
queue <pair<int,int>> q;
void work(int x,int y,int ds){
	if(x<0||x>n||y<0||y>m)
		return ;
	if(ds<dis[x][y]){
		dis[x][y]=ds;
		q.push(make_pair(x,y));
	}
}
void bfs(int o,int u,int v){
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			dis[i][j]=V-1;
	dis[u][v]=0;
	q.push(make_pair(u,v));
	while(q.empty()==0){
		int x=q.front().first,y=q.front().second;
		q.pop();
		switch(o){
			case 0:
				work(x-1,y,dis[x][y]+1);
				work(x+1,y,dis[x][y]+1);
				work(x,y-1,dis[x][y]+1);
				work(x,y+1,dis[x][y]+1);
				break;
			case 1: 
				work(x-1,y-1,dis[x][y]+1);
				work(x+1,y-1,dis[x][y]+1);
				work(x-1,y+1,dis[x][y]+1);
				work(x+1,y+1,dis[x][y]+1);
				break;
			case 2:
				for(int i=0;i<=n;i++)
					work(i,y,dis[x][y]+1);
				for(int i=0;i<=m;i++)
					work(x,i,dis[x][y]+1);
				break;
			case 3:
				work(x-2,y-1,dis[x][y]+1);
				work(x+2,y-1,dis[x][y]+1);
				work(x-2,y+1,dis[x][y]+1);
				work(x+2,y+1,dis[x][y]+1);
				work(x-1,y-2,dis[x][y]+1);
				work(x+1,y-2,dis[x][y]+1);
				work(x-1,y+2,dis[x][y]+1);
				work(x+1,y+2,dis[x][y]+1);
				break;
			case 4:
				work(x-2,y-2,dis[x][y]+1);
				work(x+2,y-2,dis[x][y]+1);
				work(x-2,y+2,dis[x][y]+1);
				work(x+2,y+2,dis[x][y]+1);
				break;
			case 5:
				work(x+1,y,dis[x][y]+1);
				if(x>4){
					work(x,y-1,dis[x][y]+1);
					work(x,y+1,dis[x][y]+1);
				}
				break;
		}
	}
}
void init(){
	for(int o=0;o<B;o++)
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
				bt[o][6*((m+1)*i+j)+o]=1;
	for(int o=0;o<B;o++)
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++){
				bfs(o,i,j);
				for(int x=0;x<=n;x++)
					for(int y=0;y<=m;y++)
						bs[x][y][dis[x][y]][6*((m+1)*i+j)+o]=1;
			}
}
int ans;
int dfs(int c,bitset <N> b,bool op){
	for(int o=0;o<B;o++)
		if((b&bt[o])==b){
			if(op){
				while(ans--){
					printf("? 0 0\n");
					fflush(stdout);
					int x;
					scanf("%d",&x);
				}
				printf("! %c\n",s[o]);
				fflush(stdout);
			}
			return 0;
		}
	if(c>3)
		return 1;
	int mx=5-c,x=0,y=0;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++){
			int res=0;
			for(int k=0;k<V;k++){
				if((b&bs[i][j][k]).any())
					res=max(res,dfs(c+1,b&bs[i][j][k],0)+1);
			}
			if(res<mx)
				mx=res,x=i,y=j;
			mx=min(mx,res+1);
		}
	if(op){
		if(c==1){
			ans=mx;
			printf("%d\n",ans);
		}
		printf("? %d %d\n",x,y);
		fflush(stdout);
		int k;
		scanf("%d",&k);
		if(k==-1)
			k=V-1;
		ans--;
		dfs(c+1,b&bs[x][y][k],1);
	} 
	return mx;
}
void solve(){
	int T;
	scanf("%d",&T);
	bitset <N> b;
	while(T--){
		int x,y;
		scanf("%d%d",&x,&y);
		for(int o=0;o<B;o++)
			b[6*((m+1)*x+y)+o]=1;
	}
	dfs(1,b,1);
}
int main(){
	init();
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 137ms
memory: 4244kb

input:

1
9 0
8

output:

1
? 1 8
! S

result:

ok number is guessed.

Test #2:

score: 0
Accepted
time: 386ms
memory: 4240kb

input:

4
2 1
2 3
2 5
2 7
5
1

output:

2
? 0 0
? 0 6
! M

result:

ok number is guessed.

Test #3:

score: 0
Accepted
time: 129ms
memory: 3964kb

input:

1
2 4
-1
1

output:

2
? 0 0
? 0 2
! X

result:

ok number is guessed.

Test #4:

score: 0
Accepted
time: 132ms
memory: 4032kb

input:

1
5 0
6

output:

1
? 3 6
! S

result:

ok number is guessed.

Test #5:

score: 0
Accepted
time: 126ms
memory: 4032kb

input:

1
6 0
6

output:

1
? 0 2
! S

result:

ok number is guessed.

Test #6:

score: 0
Accepted
time: 233ms
memory: 3964kb

input:

2
7 7
1 0
-1
6

output:

2
? 0 0
? 7 2
! S

result:

ok number is guessed.

Test #7:

score: 0
Accepted
time: 550ms
memory: 3956kb

input:

5
8 6
1 3
0 5
2 4
0 2
6
3

output:

2
? 0 0
? 0 3
! J

result:

ok number is guessed.

Test #8:

score: 0
Accepted
time: 562ms
memory: 3972kb

input:

6
0 7
1 6
2 8
0 5
7 6
8 2
-1
14

output:

2
? 0 0
? 8 1
! B

result:

ok number is guessed.

Test #9:

score: 0
Accepted
time: 793ms
memory: 4244kb

input:

7
6 5
3 0
3 2
4 1
4 0
2 4
5 2
5
7

output:

2
? 0 0
? 0 4
! J

result:

ok number is guessed.

Test #10:

score: 0
Accepted
time: 952ms
memory: 4252kb

input:

8
3 3
2 5
6 2
7 4
1 4
3 0
2 4
3 4
7
-1

output:

2
? 0 1
? 0 0
! S

result:

ok number is guessed.

Test #11:

score: 0
Accepted
time: 930ms
memory: 3980kb

input:

9
2 7
2 4
2 5
2 2
2 1
2 0
2 6
2 3
2 8
6
8

output:

2
? 2 0
? 0 0
! J

result:

ok number is guessed.

Test #12:

score: 0
Accepted
time: 879ms
memory: 3892kb

input:

10
4 0
0 0
5 0
7 0
8 0
1 0
6 0
9 0
2 0
3 0
9
-1

output:

2
? 9 0
? 0 1
! B

result:

ok number is guessed.

Test #13:

score: 0
Accepted
time: 862ms
memory: 4236kb

input:

9
1 8
1 2
1 5
1 6
1 3
1 4
1 0
1 1
1 7
6
7

output:

2
? 1 0
? 0 0
! J

result:

ok number is guessed.

Test #14:

score: -100
Time Limit Exceeded

input:

10
0 4
5 4
8 4
2 4
4 4
7 4
3 4
9 4
6 4
1 4
11
5

output:

2
? 9 1
? 0 0
! J

result: