QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430355 | #8742. 黑白 | ANewZhiyangfan# | TL | 0ms | 0kb | C++14 | 1.6kb | 2024-06-03 18:34:26 | 2024-06-03 18:34:27 |
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));
while (!q.empty()) {
auto tmp = q.front(); q.pop();
int x = tmp.first, y = tmp.second;
vis[x][y] = true;
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;
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 += vis[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: 0
Time Limit Exceeded
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...