QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#427075#8742. 黑白PorNPtree#AC ✓104ms53672kbC++201.1kb2024-06-01 09:18:022024-06-01 09:18:03

Judging History

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

  • [2024-06-01 09:18:03]
  • 评测
  • 测评结果:AC
  • 用时:104ms
  • 内存:53672kb
  • [2024-06-01 09:18:02]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=1e3+5,M=1e6+5,dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int T,n,m,a[N][N],d[M],cnt;
basic_string<int>g[M];
queue<int>q;
string C;
inline int W(int i,int j){return (i-1)*m+j;}
inline void add(int x,int y){g[x]+=y;}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>T;
	while(T--)
	{
		cin>>n>>m;cnt=0;
		for(int i=1;i<=n;i++)
		{
			cin>>C;
			for(int j=0;j<m;j++) cnt+=(a[i][j+1]=C[j]=='W');
		}
		if(!a[1][1]){cout<<"J\n";goto L;}
		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j])
		{
			for(int k=0;k<4;k++)
			{
				int nx=i+dx[k],ny=j+dy[k];
				if(nx<1||nx>n||ny<1||ny>m||!a[nx][ny]) continue;
				add(W(i,j),W(nx,ny));
			}
		}
		q.push(1);d[1]=1;
		while(!q.empty())
		{
			int t=q.front();q.pop();
			for(int i:g[t]) if(!d[i]) d[i]=d[t]+1,q.push(i);
		}
		if(!d[n*m]){cout<<"J\n";goto L;}
		cout<<(((cnt-d[n*m])&1)?"I\n":"J\n");
L:		for(int i=1;i<=n*m;i++) g[i].clear(),d[i]=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 104ms
memory: 53672kb

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