QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#425344 | #8742. 黑白 | ucup-team2279# | AC ✓ | 78ms | 8244kb | C++17 | 956b | 2024-05-30 09:02:53 | 2024-05-30 09:02:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr array<array<int, 2>, 4> dir{{{0, 1}, {1, 0}, {0, -1}, {-1, 0}}};
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<char>> g(n, vector<char>(m));
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> g[i][j];
cnt += g[i][j] == 'W';
}
}
queue<array<int, 2>> q;
vector<vector<int>> vis(n, vector<int>(m));
if (g[0][0] == 'W') {
vis[0][0] = 1;
q.push({0, 0});
}
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
for (auto [dx, dy] : dir) {
int nx = x + dx, ny = y + dy;
if (nx < 0 || ny < 0 || nx >= n || ny >= m || vis[nx][ny] || g[nx][ny] == 'B') continue;
vis[nx][ny] = 1;
q.push({nx, ny});
}
}
cout << (!vis[n - 1][m - 1] ? 'J' : (cnt - n - m - 1 & 1 ? 'I' : 'J')) << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 78ms
memory: 8244kb
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