QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235246#1811. How to Move the BeansPBYWA 4ms30076kbC++142.8kb2023-11-02 16:25:232023-11-02 16:25:23

Judging History

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

  • [2023-11-02 16:25:23]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:30076kb
  • [2023-11-02 16:25:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000+5;
int n,m;
char mp[N][N];
namespace task1{
	const int N=20+5;
	int sg[N][N][N];
	bool ins[N][N][N];
	bool pd(){
		return n<=20&&m<=20;
	}
	int getsg(int x,int y,int d){
		if(ins[x][y][d]) return sg[x][y][d];
//		cout<<x<<' '<<y<<' '<<d<<'\n';
		set<int> st;st.clear();
		int nwy=y+d;
		nwy+=m*(nwy>m?-1:(nwy<1?1:0));
		if(abs(d)+1<m&&d>=0&&mp[x][nwy%m+1]!='#') st.insert(getsg(x,y,d+1));
		if(abs(d)+1<m&&d<=0&&mp[x][(nwy-1<1?m:nwy-1)]!='#') st.insert(getsg(x,y,d-1));
		if(x<n) st.insert(getsg(x+1,nwy,0));
		int p=0;
		while(st.count(p)) p++;
		ins[x][y][p]=true;
		return sg[x][y][d]=p;
	}
	void solve(){
		memset(ins,0,sizeof(ins));
		int ans=0;
		for(int i=1;i<=n;i++)	
			for(int j=1;j<=m;j++)
				if(mp[i][j]=='B') ans^=getsg(i,j,0);
		if(!ans) cout<<"Bob\n";
		else cout<<"Alice\n";
		return ;
	}
}
namespace task2{
	vector<int> e[N*N];
	int sg[N*N],ins[N*N];
	int tt=1,id[N][N],is[N*N];
	void prework(){
		for(int i=1;i<=n;i++){
			int st=tt;
			for(int j=1,lst=0;j<=m+1;j++){
				if(mp[i][j]=='#'||j==m+1) tt++;
				else id[i][j]=tt,is[tt]^=1;
			}
			if(st==tt-1) continue;
			for(int j=m,p=tt-1;id[i][j]==p;j--)
				is[st]^=1,id[i][j]=st;
		}
		tt--;
		for(int i=1;i<n;i++)
			for(int j=1;j<=m;j++)
				if(mp[i][j]!='#'&&mp[i+1][j]!='#')
					e[id[i][j]].push_back(id[i+1][j]);
		for(int i=1;i<=tt;i++)
			sort(e[i].begin(),e[i].end()),
			e[i].resize(unique(e[i].begin(),e[i].end())-e[i].begin());
		return ;
	}
	int getsg(int k){
		if(ins[k]) return sg[k];
		set<int> st;st.clear();
		for(int to:e[k])
			st.insert(getsg(to));
		int p=0;
		while(st.count(p)) p++;
		if(!is[k]) st.insert(p);
		while(st.count(p)) p++;
		ins[k]=true,sg[k]=p;
		return p;
	}
	void solve(){
		int ans=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(mp[i][j]=='B') ans^=getsg(id[i][j]);
		if((!ans)^(rand()&1)) cout<<"Bob\n";
		else cout<<"Alice\n";
		return ;
	}
}
namespace task3{
	bool pd(){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(mp[i][j]=='#') return false;
		return true;
	}
	void solve(){
//		cout<<(m&1)<<' ';
		if(m&1) cout<<"Bob\n";
		else{
			int ans=0;
			for(int i=1;i<=n;i++)
				for(int j=1;j<=m;j++)
					if(mp[i][j]=='B') ans^=(n-i+1)&1;
			if(!ans) cout<<"Bob\n";
			else cout<<"Alice\n";
		}
	}
}
int main(){
	// freopen("chequer.in","r",stdin);
	// freopen("chequer.out","w",stdout);
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(false);
	srand(time(NULL));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>mp[i]+1;
	if(task3::pd()) 
//			cout<<"t1 :",
		task3::solve();
	else if(task1::pd()) 
//			cout<<"t2 :",
		task1::solve();
	else task2::solve();
	return 0;
}
/*
3
2 3
B.#
#..
1 1
B
1 3
B#.

*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 28112kb

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

score: 0
Accepted
time: 0ms
memory: 28804kb

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

score: 0
Accepted
time: 4ms
memory: 28980kb

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

score: 0
Accepted
time: 0ms
memory: 28768kb

input:

5 18
#.#..#.#..###..###
##...#.#..#.#..#..
#....#.#..###..#..
##...#.#..#....#..
#.#..###..#....###

output:

Bob

result:

ok "Bob"

Test #5:

score: -100
Wrong Answer
time: 4ms
memory: 30076kb

input:

293 249
#B..B..BBB..B.B.B...#BBB..B#B.BBB.#B##B.BB.B.##B#B.BB..B.#B#BB.BB##B#BB#...B..BB..B.B##B.B#B.#.##..B.#..BBBB#.BB..#.BBB#B##BB....B.##B..#...B#..B.BB#B.#...B#.BB.#B#.B...BBB.B.B..B....##.B..B##.BB#B.B.BBB.B#B..#.B.B#.B##..B#.##BB.#BB#.BB.#.B..BB.BB.B
BB.B.#.B#BB.B.B..B.###.B...BB.##.B...B#BB....

output:

Bob

result:

wrong answer 1st words differ - expected: 'Alice', found: 'Bob'