QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#427708 | #8742. 黑白 | xhgua | AC ✓ | 76ms | 15100kb | C++14 | 1.2kb | 2024-06-01 15:09:13 | 2024-06-01 15:09:13 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 1e3 + 5, dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int T, n, m;
bool vis[N][N];
char a[N][N];
void dfs(int x, int y) {
if (vis[x][y]) return;
vis[x][y] = true;
for (int d = 0; d < 4; d++) {
int nx = x + dx[d], ny = y + dy[d];
if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] != 'W') continue;
dfs(nx, ny);
}
}
void solve() {
std::cin >> n >> m;
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) std::cin >> a[i][j];
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) vis[i][j] = false;
if (a[1][1] != 'W' || a[n][m] != 'W') {
std::cout << "J" << "\n";
return;
}
dfs(1, 1);
if (!vis[n][m]) {
std::cout << "J" << "\n";
return;
}
int cnt = 0;
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cnt += (a[i][j] == 'W');
if (cnt % 2 == (n + m - 1) % 2) std::cout << "J" << "\n";
else std::cout << "I" << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> T;
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 76ms
memory: 15100kb
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