QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424356 | #8742. 黑白 | wsyear | AC ✓ | 42ms | 21712kb | C++17 | 1.5kb | 2024-05-29 08:27:46 | 2024-05-29 08:27:47 |
Judging History
answer
// Author: Klay Thompson
// Problem: D. 黑白
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int maxn = 1010;
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int n, m, vis[maxn][maxn];
char s[maxn][maxn];
void dfs(int x, int y) {
vis[x][y] = 1;
rep (k, 0, 3) {
int tx = x + dx[k], ty = y + dy[k];
if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
if (s[tx][ty] == 'W' && !vis[tx][ty]) dfs(tx, ty);
}
}
void work() {
cin >> n >> m;
rep (i, 1, n) cin >> (s[i] + 1);
rep (i, 1, n) rep (j, 1, m) vis[i][j] = 0;
if (s[1][1] == 'B') return cout << "J\n", void();
dfs(1, 1);
if (!vis[n][m]) return cout << "J\n", void();
int cnt = 0;
rep (i, 1, n) rep (j, 1, m) cnt += (s[i][j] == 'W');
if ((cnt & 1) ^ ((n + m) & 1)) cout << "J\n";
else cout << "I\n";
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
int t; cin >> t;
while (t--) work();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 42ms
memory: 21712kb
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