QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#440079 | #8742. 黑白 | james1BadCreeper | AC ✓ | 46ms | 15460kb | C++17 | 1.1kb | 2024-06-13 07:19:50 | 2024-06-13 07:19:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 1e3 + 5;
const int D[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int n, m;
bool vis[N][N];
char a[N][N];
void bfs(int x, int y) {
vis[x][y] = 1;
for (int i = 0; i < 4; ++i) {
int xx = x + D[i][0], yy = y + D[i][1];
if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && !vis[xx][yy] && a[xx][yy] == 'W')
bfs(xx, yy);
}
}
void solve(void) {
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i] + 1;
for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) vis[i][j] = 0;
bfs(1, 1);
if (!vis[n][m]) return cout << "J\n", void();
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
ans += (a[i][j] == 'W');
// cerr << ans << "\n";
if ((ans - (n + m - 1)) & 1) cout << "I\n";
else cout << "J\n";
}
int main(void) {
ios::sync_with_stdio(0); cin.tie(0);
int T = 1; cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 46ms
memory: 15460kb
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