QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#440079#8742. 黑白james1BadCreeperAC ✓46ms15460kbC++171.1kb2024-06-13 07:19:502024-06-13 07:19:51

Judging History

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

  • [2024-06-13 07:19:51]
  • 评测
  • 测评结果:AC
  • 用时:46ms
  • 内存:15460kb
  • [2024-06-13 07:19:50]
  • 提交

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