QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#442307#8742. 黑白MindevelopedAC ✓90ms7528kbC++141.0kb2024-06-15 11:02:052024-06-15 11:02:06

Judging History

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

  • [2024-06-15 11:02:06]
  • 评测
  • 测评结果:AC
  • 用时:90ms
  • 内存:7528kb
  • [2024-06-15 11:02:05]
  • 提交

answer

#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
const int N=1e3+5;
string s[N];
bool pass[N][N],vis[N][N];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//I first J second
void solve(){
	int n,m,cnt=0;cin>>n>>m;
	for(int i=0;i<=n+1;i++){
		for(int j=0;j<=m+1;j++){
			pass[i][j]=0,vis[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>s[i];
		for(int j=1;j<=m;j++){
			pass[i][j]=(s[i][j-1]=='W');
			cnt+=pass[i][j];
		}
	}
	if(!pass[1][1] || !pass[n][m]){
		cout<<"J\n";
		return ;
	}
	queue<pii> Q;
	Q.push(mp(1,1));
	vis[1][1]=1;
	while(!Q.empty()){
		pii pre=Q.front();Q.pop();
		int x=pre.first,y=pre.second;
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(pass[nx][ny] && !vis[nx][ny]){
				Q.push(mp(nx,ny));
				vis[nx][ny]=1;
			}
		}
	}
	if(!vis[n][m]){
		cout<<"J\n";
		return ;
	}
	if(cnt%2==(n+m-1)%2){
		cout<<"J\n";
	}
	else{
		cout<<"I\n";
	}
}
int main(){
	int T;cin>>T;
	while(T--){
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 90ms
memory: 7528kb

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