QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770189#8742. 黑白ayaAC ✓45ms8868kbC++23876b2024-11-21 21:01:572024-11-21 21:01:57

Judging History

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

  • [2024-11-21 21:01:57]
  • 评测
  • 测评结果:AC
  • 用时:45ms
  • 内存:8868kb
  • [2024-11-21 21:01:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0};
int n,m;char s[1004][1004];
int c,v[1004][1004];
bool check(){
    if(s[1][1]=='B')return 0;
    queue<pii>que;
    v[1][1]=c,que.push({1,1});
    while(!que.empty()){
        auto[x,y]=que.front();que.pop();
        for(int d=0;d<4;d++){
            int xx=x+dx[d],yy=y+dy[d];
            if(!xx||!yy||xx>n||yy>m||s[xx][yy]=='B'||v[xx][yy]==c)continue;
            if(xx==n&&yy==m)return 1;
            v[xx][yy]=c,que.push({xx,yy});
        }
    }
    return 0;
}
void sol(){
    cin>>n>>m,++c;
    for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
    if(!check()){puts("J");return;}
    int sm=n+m;
    for(int i=1;i<=n;i++)sm+=count(s[i]+1,s[i]+m+1,'W');
    puts(sm&1?"J":"I");
}
int main(){int tc;scanf("%d",&tc);while(tc--)sol();}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 45ms
memory: 8868kb

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