QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442111#8742. 黑白Jowaire#AC ✓47ms29484kbC++14988b2024-06-15 08:32:462024-06-15 08:32:47

Judging History

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

  • [2024-06-15 08:32:47]
  • 评测
  • 测评结果:AC
  • 用时:47ms
  • 内存:29484kb
  • [2024-06-15 08:32:46]
  • 提交

answer

# include <bits/stdc++.h>

const int N=100010,INF=0x3f3f3f3f;

inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-') f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}

char s[1010][1010];

bool vis[1010][1010];

int n,m;

bool dfs(int i,int j){
	if(i==n&&j==m) return true;
	if(vis[i][j]||s[i][j]!='W') return false;
	vis[i][j]=true;
	for(int x=i-1;x<=i+1;++x){
		for(int y=j-1;y<=j+1;++y){
			if(abs(x-i)+abs(y-j)==1&&x>=1&&x<=n&&y>=1&&y<=m&&!vis[x][y]){
				if(dfs(x,y)) return true; 
			}
		}
	}
	return false;
}

int main(void){
	int T=read();
	while(T--){
		n=read(),m=read();
		
		int ans=0;
		
		for(int i=1;i<=n;++i){
			scanf("%s",s[i]+1);
			for(int j=1;j<=m;++j) ans+=(s[i][j]=='W'),vis[i][j]=false;
		}
		
		if(!dfs(1,1)){
			puts("J");
			continue;
		}
		
		int d=(n+m-1-ans)&1;
		
		if(d) puts("I");
		else puts("J");
		
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 47ms
memory: 29484kb

input:

100
2 6
WWBBWW
WWWWWB
3 8
WWWBBBBB
WWWBWWWB
BBWWWBWW
5 2
WB
BB
BB
BW
BB
6 4
WWBW
WBWB
WWWW
WWWB
BBWW
BWBW
2 3
WWW
WBW
124 125
BWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWBWWWWWWWWBWWWWWWWWWWWBBBBWWWWWWWWWWWWWWWWWBWWWWWWWWWBWWWWWWWWWWBWWWWWWWWBBWWWWWWWWWWWWWWWWWWB
WWWWWWWBWWBWWWWWWWWWWWBWWBWWBWWWWBWWWWWWWWWBWBWB...

output:

J
J
J
I
I
J
I
I
I
J
I
J
J
J
J
J
I
I
I
I
J
J
I
I
I
J
J
I
J
J
J
J
I
J
J
J
J
J
J
I
J
J
I
I
I
J
J
I
J
J
J
I
J
I
J
J
J
J
I
I
J
J
J
I
J
J
I
J
I
I
J
J
J
I
J
I
I
J
J
I
J
J
J
J
J
I
J
J
J
I
I
J
J
I
I
J
J
J
J
I

result:

ok 100 lines