QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715107#9537. Chinese Chessas_lyrTL 712ms4268kbC++142.8kb2024-11-06 10:28:192024-11-06 10:28:19

Judging History

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

  • [2024-11-06 10:28:19]
  • 评测
  • 测评结果:TL
  • 用时:712ms
  • 内存:4268kb
  • [2024-11-06 10:28:19]
  • 提交

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++)
				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;
}

详细

Test #1:

score: 100
Accepted
time: 251ms
memory: 4044kb

input:

1
9 0
8

output:

1
? 1 8
! S

result:

ok number is guessed.

Test #2:

score: 0
Accepted
time: 712ms
memory: 4268kb

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: 243ms
memory: 4248kb

input:

1
2 4
-1
1

output:

2
? 0 0
? 0 2
! X

result:

ok number is guessed.

Test #4:

score: 0
Accepted
time: 230ms
memory: 3992kb

input:

1
5 0
6

output:

1
? 3 6
! S

result:

ok number is guessed.

Test #5:

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

input:

1
6 0
6

output:

1
? 0 2
! S

result:

ok number is guessed.

Test #6:

score: 0
Accepted
time: 427ms
memory: 3960kb

input:

2
7 7
1 0
-1
6

output:

2
? 0 0
? 7 2
! S

result:

ok number is guessed.

Test #7:

score: -100
Time Limit Exceeded

input:

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

output:

2
? 0 0
? 0 3
! J

result: