QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442460#8742. 黑白rgw2010#AC ✓68ms6552kbC++141.7kb2024-06-15 12:12:292024-06-15 12:12:29

Judging History

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

  • [2024-06-15 12:12:29]
  • 评测
  • 测评结果:AC
  • 用时:68ms
  • 内存:6552kb
  • [2024-06-15 12:12:29]
  • 提交

answer

#include<bits/stdc++.h>
#define Add(x,y) (x+y>=mod)?(x+y-mod):(x+y)
#define lowbit(x) x&(-x)
#define full(l,r,x) for(auto it=l;it!=r;it++) (*it)=x
#define Full(a) memset(a,0,sizeof(a))
#define open(s1,s2) freopen(s1,"r",stdin),freopen(s2,"w",stdout);
using namespace std;
typedef double db;
typedef long long ll;
const ll N=1010;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')
          f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
inline void write(ll x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9)
	  write(x/10);
	putchar(x%10+'0');
}
inline char get(){
	char c;
	while(1){
		c=getchar();
		if(c=='W'||c=='B')
		  break;
	}
	return c;
}
ll T,n,m,s;
bool f[N][N],dis[N][N],F[N][N];
ll dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void bfs(ll sx,ll sy){
	queue<pair<ll,ll>> Q;
	Q.push({sx,sy});
	dis[sx][sy]=1;
	while(!Q.empty()){
		ll x=Q.front().first,y=Q.front().second;
		Q.pop();
		if(F[x][y])
		  continue;
		F[x][y]=1;
		for(int i=0;i<4;i++){
			ll zx=x+dx[i],zy=y+dy[i];
			if(zx<1||zx>n||zy<1||zy>m)
			  continue;
			if(f[zx][zy])
			  continue;
			if(dis[zx][zy])
			  continue;
			dis[zx][zy]=1;
			Q.push({zx,zy});
		}
	}
}
void solve(){
	s=0;
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(get()=='W'){
				f[i][j]=0;
				s++;
			}
			else
			  f[i][j]=1;
			dis[i][j]=F[i][j]=0;
		}
	}
	if(f[1][1]||f[n][m]){
		puts("J");
		return ;
	}
	bfs(1,1);
	if(!dis[n][m]){
		puts("J");
		return ;
	}
	if((s-n-m)&1ll)
	  puts("J");
	else
	  puts("I");
}
int main(){
	T=read();
	while(T--)
	  solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 68ms
memory: 6552kb

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