QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424389#8742. 黑白zjy0001AC ✓24ms12284kbC++17847b2024-05-29 09:10:102024-05-29 09:10:11

Judging History

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

  • [2024-05-29 09:10:11]
  • 评测
  • 测评结果:AC
  • 用时:24ms
  • 内存:12284kb
  • [2024-05-29 09:10:10]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long
using namespace std;
const int N=1e3+5;
int n,m;string S[N];
inline bool dfs(int x,int y){
    S[x][y]='B';
    if(x==n-1&&y==m-1)return 1;
    if(x>0&&S[x-1][y]!='B'&&dfs(x-1,y))return 1;
    if(y>0&&S[x][y-1]!='B'&&dfs(x,y-1))return 1;
    if(x+1<n&&S[x+1][y]!='B'&&dfs(x+1,y))return 1;
    if(y+1<m&&S[x][y+1]!='B'&&dfs(x,y+1))return 1;
    return 0;
}
inline void MAIN(){
    cin>>n>>m;int cnt=0;
    for(int i=0;i<n;++i)cin>>S[i],cnt+=count(S[i].begin(),S[i].end(),'W');
    if(S[n-1][m-1]=='B'||!dfs(0,0))cout<<"J\n";
    else cout<<((cnt+n+m)&1?"J\n":"I\n");
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int t=1;cin>>t;while(t--)MAIN();
    return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 12284kb

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