QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430359 | #8742. 黑白 | ANewZhiyangfan# | AC ✓ | 59ms | 8636kb | C++14 | 1.6kb | 2024-06-03 18:37:01 | 2024-06-03 18:37:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int dx[] = {1, -1, 0, 0},
dy[] = {0, 0, 1, -1};
int T, n, m, a[N][N];
bool vis[N][N];
queue< pair<int, int> > q;
char s[N];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (int j = 1; j <= m; ++j) {
char ch = s[j];
if (ch == 'W') a[i][j] = 1;
else a[i][j] = 0;
vis[i][j] = false;
}
}
if (a[1][1] != 1 || a[n][m] != 1) {
puts("J");
continue;
}
q.push(make_pair(1, 1)); vis[1][1] = true;
while (!q.empty()) {
auto tmp = q.front(); q.pop();
int x = tmp.first, y = tmp.second;
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 1 || nx > n) continue;
if (ny < 1 || ny > m) continue;
if (vis[nx][ny]) continue;
if (!a[nx][ny]) continue;
vis[nx][ny] = true;
q.push(make_pair(nx, ny));
}
}
if (!vis[n][m]) {
puts("J");
continue;
}
int sum = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
sum += a[i][j];
sum -= n + m - 1;
if (sum & 1) puts("I");
else puts("J");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 59ms
memory: 8636kb
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