QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235234 | #1811. How to Move the Beans | PBY | WA | 5ms | 32344kb | C++14 | 2.8kb | 2023-11-02 16:20:24 | 2023-11-02 16:20:25 |
Judging History
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: 28300kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 0ms
memory: 30508kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 28272kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 4ms
memory: 28328kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 5ms
memory: 30284kb
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:
Alice
result:
ok "Alice"
Test #6:
score: 0
Accepted
time: 0ms
memory: 32344kb
input:
75 13 BBB.B.BB.B.#B BB.##...B##BB ..#.B....#.B. BBB..#...B#BB #B#.##B..BB.. #B..BBBB.B..# #B##.BBBBB.B# BBB.B..#B#B.. .BBB####.##BB .B##...#.#.#. #.BB#..B.B.B. BB#BB.BBB..BB B.#...#.BBBBB ..#B.BBBB..B# BB..B..#..... ..B..BBBB.B#. .B.B##B.#B.## BBBB#...#..B# B.BB..BBB#B.B .#B#B...BB.BB #.B...BB...B. ...
output:
Alice
result:
ok "Alice"
Test #7:
score: 0
Accepted
time: 0ms
memory: 30284kb
input:
35 38 #.#..B.B.#.BB#.B.B.B..##..B#B###BBB##. .#.#.B#.#BBB..B..BB.#..BB..##B......#B B.B#..B..B...##B#B..#.##.#..B.#..B##BB #.B.B..#..B#.#.B#B##B.BBB..#.B...B..#. B#.#.BBB..B.BB.B..BBBBB##B..BB#.B#.BB. B##.B#...B.B.BB.BBB..#BBB.#..#B#.B..#B B....B#B.#.BBB.B#BB...##B#...B..BB.BB. ..###.#.B#....#.....#...
output:
Alice
result:
ok "Alice"
Test #8:
score: 0
Accepted
time: 0ms
memory: 30796kb
input:
36 106 BB.B..B.BBBB.BB..BB..BB..BB...BB.B..B.B..BBBB.B.BB..B.B..BB..BBBB.B.B.BBBB..B.BBBBBBBBBBBBBBB.BB.B.BBB..BB #BBB.BBB#..#.BB...###B.B#.B...B.#.BBBB.B..B..#B.#B#BB##.BB.#B..B#B...B....B#B#.#B.B.B.BB#..B#B#.#.#B###.B. B.BBB.BBBBB.BBB....BB..B.BBBB.BBB.BBB.BBB.B.B.BBB.B...B.B.BBBBB.BBB....BB.BBB.B...
output:
Alice
result:
ok "Alice"
Test #9:
score: 0
Accepted
time: 5ms
memory: 30656kb
input:
245 239 .BBB.BB.B.BBB..B.BB.BBBBBB..B.BBB.B.BBBBBBBBB..B..BB.B.B.BB..B.BB...B.BB.B.BB..BBB..BB..BB.BBB.BBB.BBBBB.BBBB.BB.BBBB...BBB.B..BBBBBBB..BB..B.B.B..BBBBB...BB..BBB...BBB.B..BB.BB.B.BB.BBB..B.B.BBBB.BBBBB.BBB.BBBB.BB...B.B.B...BBB.BBB.BBB..B B#.#BB..#BB.BBB#..BB..#.B#.##B.BBB###..B#B...BB..#.#...
output:
Bob
result:
ok "Bob"
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 30560kb
input:
288 94 B....BB....BB.BBB.BBBB..B.B.B.....BBBB.B..BBBBBB.B..BBBBBBB....BBB.BBBBB.B.BBBB..B..B.B.BBB..B BB#.#B#BBB.B#BB..BBB.B#BB#B#BB#BBBBBB####.B.B...BBB.BB.B.#.B.B.B.#.B.B.#.#..B..BB..B#..B.#.... BBBBBBB...B.BB.B..BB..BBBB.BBBBB.BBBB..BBBBBB.BB....B.BBBB.BB.BBB..B.BBBB.B.BBBBBB..BBB.BBB.B. .B....B....
output:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'