QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232299 | #1811. How to Move the Beans | c20230201 | WA | 1ms | 7176kb | C++14 | 3.1kb | 2023-10-30 09:43:52 | 2023-10-30 09:43:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char a[1005][1005];
int t[1005];
int sg[1005][1005];
int L[1005], R[1005];
int nl[1005], nr[1005];
int tl[4][1005], tr[4][1005], rl[4][1005], rr[4][1005];
int mex(int x,int y) {
if(x>y) swap(x,y);
if(x) return 0;
if(y>1) return 1;
return 2;
}
int mex2(int x,int y,int z) {
if(y<x) swap(x,y);
if(z<x) swap(x,z);
if(z<y) swap(y,z);
if(x) return 0;
if(y>1) return 1;
if(z>2) return 2;
return 3;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n,m; cin>>n>>m;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
cin>>a[i][j];
if(a[i][j]=='#') sg[i][j]=3;
}
}
for(int i=1;i<m;i++) nr[i]=i+1;
for(int i=2;i<=m;i++) nl[i]=i-1;
nr[m]=1, nl[1]=m;
for(int i=1;i<=m;i++) sg[n+1][i]=3;
for(int i=n;i>=1;i--) {
int tot=0;
for(int j=1;j<=m;j++) if(a[i][j]=='#') t[++tot]=j;
if(tot) {
for(int j=1;j<=tot;j++) {
int l,r;
if(j!=1) l=nr[t[j-1]], r=nl[t[j]];
else l=nr[t[tot]], r=nl[t[j]];
if(l==t[j]) continue;
else if(l==r) {
sg[i][l]=(!sg[i+1][l]);
continue;
} else {
L[l]=(!sg[i+1][l]);
R[r]=(!sg[i+1][r]);
for(int k=nr[l];;k=nr[k]) {
L[k]=mex(L[nl[k]],sg[i+1][k]);
if(k==r) break;
}
for(int k=nl[r];;k=nl[k]) {
R[k]=mex(R[nr[k]],sg[i+1][k]);
if(k==l) break;
}
for(int k=l;;k=nr[k]) {
if(k==l) sg[i][k]=mex(R[nr[k]],sg[i+1][k]);
else if(k==r) sg[i][k]=mex(L[nl[k]],sg[i+1][k]);
else sg[i][k]=mex2(L[nl[k]],R[nr[k]],sg[i+1][k]);
if(k==r) break;
}
}
}
}else {
if(m==1) {
sg[i][1]=(!sg[i+1][1]);
continue;
}
for(int t=0;t<=3;t++) {// L[m]=t, L[j]=?
int lst=t;
for(int j=1;j<m;j++) tl[t][j]=mex(lst,sg[i+1][j]), lst=tl[t][j];
}
for(int t=0;t<=3;t++) {// R[1]=t, R[j]=?
int lst=t;
for(int j=m;j>1;j--) tr[t][j]=mex(lst,sg[i+1][j]), lst=tr[t][j];
}
for(int t=0;t<=3;t++) rl[t][m]=t;
for(int j=m-1;j>=1;j--) {// sg[i][j]=t, L[m]=?
for(int t=0;t<=3;t++) {
int pl=mex(t,sg[i+1][j+1]);
rl[t][j]=rl[pl][j+1];
}
}
for(int t=0;t<=3;t++) rr[t][1]=t;
for(int j=2;j<=m;j++) {// sg[i][j]=t, R[1]=?
for(int t=0;t<=3;t++) {
int pr=mex(t,sg[i+1][j-1]);
rr[t][j]=rr[pr][j-1];
}
}
for(int j=1;j<=m;j++) {
if(j==1) {
L[2]=(!sg[i+1][2]), R[m]=(!sg[i+1][m]);
for(int k=3;k<=m;k++) L[k]=mex(L[nl[k]],sg[i+1][k]);
for(int k=m-1;k>=2;k--) R[k]=mex(R[nr[k]],sg[i+1][k]);
sg[i][j]=mex2(L[m],R[2],sg[i+1][j]);
}else if(j==m) {
L[m]=R[m]=0;
for(int k=1;k<m;k++) L[k]=mex(L[nl[k]],sg[i+1][k]);
for(int k=m-1;k>=1;k--) R[k]=mex(R[nr[k]],sg[i+1][k]);
sg[i][j]=mex2(L[1],R[m-1],sg[i+1][j]);
}else {
int pl=(!sg[i+1][j-1]), pr=(!sg[i+1][j+1]);
sg[i][j]=mex2(sg[i+1][j],tl[rl[pr][j+1]][j-1],tr[rr[pl][j-1]][j+1]);
}
}
}
}
int ans=0;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(a[i][j]=='B') ans^=sg[i][j];
// cout<<sg[i][j]<<' ';
}
// cout<<'\n';
}
if(ans) cout<<"Alice\n";
else cout<<"Bob\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
2 3 B.# #..
output:
Alice
result:
ok "Alice"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
1 1 B
output:
Bob
result:
ok "Bob"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
1 3 B#.
output:
Alice
result:
ok "Alice"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
5 18 #.#..#.#..###..### ##...#.#..#.#..#.. #....#.#..###..#.. ##...#.#..#....#.. #.#..###..#....###
output:
Bob
result:
ok "Bob"
Test #5:
score: 0
Accepted
time: 0ms
memory: 7176kb
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: -100
Wrong Answer
time: 1ms
memory: 4032kb
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:
Bob
result:
wrong answer 1st words differ - expected: 'Alice', found: 'Bob'