QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442171 | #8742. 黑白 | FAKUMARER# | AC ✓ | 203ms | 5520kb | C++14 | 1.3kb | 2024-06-15 09:39:31 | 2024-06-15 09:39:32 |
Judging History
answer
#include <bits/stdc++.h>
const int MAXN = 1005;
using namespace std;
char Mp[MAXN][MAXN];
bool Vis[MAXN][MAXN];
struct Point {
int x, y;
};
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
int N, M;
inline bool BFS () {
std::queue <Point> Q;
Q.push ({1, 1});
Point Now;
while (!Q.empty ()) {
Now = Q.front (), Q.pop ();
if (Vis[Now.x][Now.y]) continue ;
if (Now.x == N && Now.y == M) return 1;
Vis[Now.x][Now.y] = 1;
for (int i = 0; i < 4; ++ i) {
if (Now.x + dx[i] < 1 || Now.x + dx[i] > N || Now.y + dy[i] < 1 || Now.y + dy[i] > M) continue ;
if (Mp[Now.x + dx[i]][Now.y + dy[i]] == 'W') Q.push ({Now.x + dx[i], Now.y + dy[i]});
}
}
return 0;
}
inline void Solve () {
memset (Vis, 0, sizeof Vis);
cin >> N >> M;
for (int i = 1; i <= N; ++ i)
for (int j = 1; j <= M; ++ j)
cin >> Mp[i][j];
bool IsC = BFS ();
if (!IsC) return cout << "J" << '\n', void ();
int Cnt = 0, Now = (N + M - 1);
for (int i = 1; i <= N; ++ i)
for (int j = 1; j <= M; ++ j)
if (Mp[i][j] == 'W') ++ Cnt;
cerr << Cnt << ' ' << Now << '\n';
if ((Cnt - Now) & 1) cout << "I" << '\n';
else cout << "J" << '\n';
}
int T;
int main () {
cin >> T;
while (T --) Solve ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 203ms
memory: 5520kb
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