QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#648125#8742. 黑白XwcAC ✓98ms4788kbC++141.3kb2024-10-17 17:09:382024-10-17 17:09:43

Judging History

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

  • [2024-10-17 17:09:43]
  • 评测
  • 测评结果:AC
  • 用时:98ms
  • 内存:4788kb
  • [2024-10-17 17:09:38]
  • 提交

answer

#include <bits/stdc++.h>

#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef double ff;
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

typedef pair<ll, ll> pii;

const int N = 1e6 + 10, M = 1e7, base = 131;

typedef struct node {
	int x, y;
} node;

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

void solve()
{
	int n, m;
	cin >> n >> m;
	
	vector<vector<char> > s(n + 1, vector<char>(m + 1));
	int cnt = 0;
	for(int i = 1; i <= n; i ++ ) {
		for(int j = 1; j <= m; j ++ ) {
			cin >> s[i][j];
			if(s[i][j] == 'W') cnt ++;
		}
	}
	
	if(s[1][1] == 'B' || s[n][m] == 'B') {
		cout << 'J' << '\n';
		return ;
	}
	
	vector<vector<bool> > vis(n + 1, vector<bool> (m + 1));
	
	queue<node> q;
	q.push({1, 1});
	
	vis[1][1] = true;
	
	while(q.size()) {
		auto t = q.front();
		q.pop();
		
		for(int i = 0; i < 4; i ++ ) {
			int x = t.x + dx[i], y = t.y + dy[i];
			if(x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && s[x][y] == 'W') {
				vis[x][y] = true;
				q.push({x, y});
			}		
		}
	}
	
	if(!vis[n][m]) {
		cout << 'J' << '\n';
		return ;
	}
	
	int have = cnt - (n + m - 1);
	if(have & 1) {
		cout << 'I' << '\n';
	} else {
		cout << 'J' << '\n';
	}
}

int main()
{
	fastio;

	int t = 1;
	cin >> t;

	while( t -- ) solve();
}

详细

Test #1:

score: 100
Accepted
time: 98ms
memory: 4788kb

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