QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#429682#8742. 黑白ieeAC ✓89ms8292kbC++17956b2024-06-02 19:15:362024-06-02 19:15:37

Judging History

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

  • [2024-06-02 19:15:37]
  • 评测
  • 测评结果:AC
  • 用时:89ms
  • 内存:8292kb
  • [2024-06-02 19:15:36]
  • 提交

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: 89ms
memory: 8292kb

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