QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#430357#8742. 黑白ANewZhiyangfan#WA 51ms8512kbC++141.6kb2024-06-03 18:36:032024-06-03 18:36:04

Judging History

你现在查看的是最新测评结果

  • [2024-06-03 18:36:04]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:8512kb
  • [2024-06-03 18:36:03]
  • 提交

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 += 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
Wrong Answer
time: 51ms
memory: 8512kb

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
J
J
J
J
I
I
J
J
J
J
J
I
I
I
J
J
I
I
I
J
J
I
J
I
J
J
J
J
J
J
J
J
J
I
J
J
I
I
J
J
J
I
I
J
J
I
J
I
J
J
J
J
J
I
I
I
J
I
J
J
I
J
I
I
J
J
J
I
J
J
I
J
J
I
J
J
J
J
J
I
J
J
J
I
I
J
J
J
I
J
J
I
J
I

result:

wrong answer 7th lines differ - expected: 'I', found: 'J'