QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524573#8742. 黑白ucup-team052AC ✓66ms8660kbC++23997b2024-08-19 20:13:162024-08-19 20:13:17

Judging History

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

  • [2024-08-19 20:13:17]
  • 评测
  • 测评结果:AC
  • 用时:66ms
  • 内存:8660kb
  • [2024-08-19 20:13:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int N = 1005;

queue < pair <int, int> > q;
char c[N][N];
int vis[N][N];
int T, n, m;

int main() {
	scanf("%d", &T);
	while (T--) {
		memset(vis, 0, sizeof(vis));
		scanf("%d%d", &n, &m);
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			scanf("%s", c[i] + 1);
			for (int j = 1; j <= m; j++) cnt += (c[i][j] == 'W');
		}
		if (c[1][1] == 'W') {
			vis[1][1] = 1; q.push(make_pair(1, 1));
		}
		while (!q.empty()) {
			pair <int, int> t = q.front(); q.pop();
			for (int d = 0; d < 4; d++) {
				int x = t.first + dx[d];
				int y = t.second + dy[d];
				if (x < 1 || y < 1 || x > n || y > m || c[x][y] == 'B' || vis[x][y]) continue;
				vis[x][y] = 1; q.push(make_pair(x, y));
			}
		}
		if (!vis[n][m]) {
			printf("J\n");
		} else if ((cnt - (n + m - 1)) % 2) {
			printf("I\n");
		} else {
			printf("J\n");
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 66ms
memory: 8660kb

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