QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720062 | #8742. 黑白 | szy10010# | AC ✓ | 114ms | 12760kb | C++20 | 1.5kb | 2024-11-07 10:28:10 | 2024-11-07 10:28:11 |
Judging History
answer
#include<iostream>
#include<set>
#include<queue>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<unordered_map>
#define pb push_back
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(),(x).end()
#define _for(i, a) for(int i = 0; i < (a); ++i)
#define _rep(i, a, b) for(int i = (a);i <= (b); ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define u1 (u<<1)
#define u2 (u<<1|1)
//#define endl '\n'
using namespace std;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
const int P=1e9+7;
const int N=1020,M=2*N;
int n,m,k,q[N];
char g[N][N];
int dist[N][N];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
void bfs()
{
memset(dist,0x3f,sizeof(dist));
queue<PII>q;
q.push({1,1});
dist[1][1]=1;
while(q.size())
{
auto t=q.front();
q.pop();
int xx=t.first,yy=t.second;
_rep(i,0,3)
{
int x=xx+dx[i],y=yy+dy[i];
if(x<1||y<1||x>n||y>m)continue;
if(dist[x][y]>dist[xx][yy]+1&&g[x][y]=='W')
{
dist[x][y]=dist[xx][yy]+1;
q.push({x,y});
}
}
}
return ;
}
void solve(){
cin>>n>>m;
int cnt=0;
_rep(i,1,n)
_rep(j,1,m)
{
cin>>g[i][j];
if(g[i][j]=='B')cnt++;
}
bfs();
if(dist[n][m]<0x3f3f3f3f/2&&g[1][1]=='W'&&g[n][m]=='W')
{
int now=n*m-cnt-dist[n][m];
if(now%2)cout<<"I\n";
else cout<<"J\n";
}
else cout<<"J\n";
}
signed main(){
IOS;
int T=1;
cin>>T;
_rep(i,1,T){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 114ms
memory: 12760kb
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