QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442304#8742. 黑白MindevelopedWA 98ms7760kbC++141.0kb2024-06-15 11:00:252024-06-15 11:00:27

Judging History

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

  • [2024-06-15 11:00:27]
  • 评测
  • 测评结果:WA
  • 用时:98ms
  • 内存:7760kb
  • [2024-06-15 11:00:25]
  • 提交

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<<"I\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<<"I\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();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 98ms
memory: 7760kb

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:

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

result:

wrong answer 1st lines differ - expected: 'J', found: 'I'