QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480409 | #8742. 黑白 | huaxiamengjin | AC ✓ | 62ms | 14568kb | C++14 | 897b | 2024-07-16 15:19:44 | 2024-07-16 15:19:46 |
Judging History
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();
}
Details
Tip: Click on the bar to expand more detailed information
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