QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480409#8742. 黑白huaxiamengjinAC ✓62ms14568kbC++14897b2024-07-16 15:19:442024-07-16 15:19:46

Judging History

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

  • [2024-07-16 15:19:46]
  • 评测
  • 测评结果:AC
  • 用时:62ms
  • 内存:14568kb
  • [2024-07-16 15:19:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[1010][1010];
bool used[1010][1010];
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
bool fl;
void dfs(int x,int y){
	if(used[x][y])return ;
	used[x][y]=1;
	for (int i=0;i<4;i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx<1||nx>n||ny<1||ny>m)continue;
		if(a[nx][ny]=='B')continue;
		dfs(nx,ny);
	}
}
void clear(){
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	used[i][j]=0;
}
void solve(){
fl=0;
	cin>>n>>m;
	int ct=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	cin>>a[i][j],ct+=(a[i][j]=='W');
	if(a[1][1]=='B'||a[n][m]=='B')
	return cout<<"J"<<"\n",void();
	dfs(1,1);
	if(used[n][m]==0)return cout<<"J\n",clear(); 
	if((ct-(n+m-1))&1)cout<<"I\n";
	else cout<<"J\n";
	return clear();
}
int main(){
	ios::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--)solve();
}

详细

Test #1:

score: 100
Accepted
time: 62ms
memory: 14568kb

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