QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235223 | #1811. How to Move the Beans | PBY | WA | 6ms | 31480kb | C++14 | 2.9kb | 2023-11-02 16:13:26 | 2023-11-02 16:13:26 |
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 clear(){
for(int i=1;i<=tt;i++)
sg[i]=ins[i]=is[i]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
id[i][j]=0;
tt=1;
return ;
}
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) cout<<"Bob\b";
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);
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#.
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 28876kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 5ms
memory: 28232kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 5ms
memory: 28516kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 0ms
memory: 28160kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 0ms
memory: 31480kb
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: 30616kb
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: 31244kb
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: 3ms
memory: 30992kb
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: -100
Wrong Answer
time: 6ms
memory: 30296kb
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\x08
result:
wrong answer 1st words differ - expected: 'Bob', found: 'Bob\x08'