QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233578#1811. How to Move the Beanssumi007WA 3ms8296kbC++143.1kb2023-10-31 19:55:172023-10-31 19:55:18

Judging History

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

  • [2023-10-31 19:55:18]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8296kb
  • [2023-10-31 19:55:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define i64 __int128
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define lowbit(i) i&(-i)
const int N = 1005;
int h,w;
char s[N][N];
int f[N][N],L[N],R[N];
int vis[5],Lt[N][5],Rt[N][5],Lf[N][5],Rf[N][5];
int pre[N],nxt[N];
int mex(int a){
    if(a) return 0;
    return 1;
}
int mex2(int a,int b){
    vis[a] = vis[b] = 1;
    int res = 0;
    while(vis[res]) res++;
    vis[a] = vis[b] = 0;
    return res;
}
int mex3(int a,int b,int c){
    vis[a] = vis[b] = vis[c] = 1;
    int res = 0;
    while(vis[res]) res++;
    vis[a] = vis[b] = vis[c] = 0;
    return res;
}
int main(){
    cin.tie(0),cout.tie(0);
    ios::sync_with_stdio(0);
    cin >> h >> w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> s[i][j];
        }
    }
    for(int j=1;j<=w;j++) f[h+1][j] = 3;
    for(int i=1;i<=w;i++) pre[i] = i-1,nxt[i] = i+1;
    pre[1] = w,nxt[w] = 1;
    for(int i=h;i>=1;i--){
        int typ = 0;
        for(int j=1;j<=w;j++) if(s[i][j]=='#') typ = 1;
        if(typ){
            for(int j=1;j<=w;j++){
                if(s[i][j]=='#'){
                    L[j] = R[j] = 3;
                    int k = pre[j];
                    while(s[i][k]!='#') R[k] = mex2(R[nxt[k]],f[i+1][k]),k = pre[k];
                    k = nxt[j];
                    while(s[i][k]!='#') L[k] = mex2(L[pre[k]],f[i+1][k]),k = nxt[k];
                }
            }
            for(int j=1;j<=w;j++){
                if(s[i][j]=='#') f[i][j] = 3;
                else f[i][j] = mex3(L[pre[j]],R[nxt[j]],f[i+1][j]);
            }
        }else{
            if(w==1){
                f[i][1] = mex(f[i+1][1]);
                continue;
            }
            for(int k=0;k<=3;k++){
                Lt[1][k] = k;
                for(int j=2;j<=w;j++) Lt[j][k] = mex2(Lt[j-1][k],f[i+1][j]);                
            } 
            for(int k=0;k<=3;k++){
                Rt[w][k] = k;
                for(int j=w-1;j>=1;j--) Rt[j][k] = mex2(Rt[j+1][k],f[i+1][j]);
            }
            for(int k=0;k<=3;k++) Lf[w][k] = k;
            for(int j=1;j<w;j++){
                for(int k=0;k<=3;k++){
                    Lf[j][mex2(k,f[i+1][j])] = Lf[pre[j]][k];
                }
            }   
            for(int k=0;k<=3;k++) Rf[1][k] = k;
            for(int j=w;j>1;j--){
                for(int k=0;k<=3;k++){
                    Rf[j][mex2(k,f[i+1][j])] = Rf[nxt[j]][k];
                }
            }
            f[i][1] = mex3(Lf[2][mex(f[i+1][2])],Rt[2][mex(f[i+1][w])],f[i+1][1]);
            f[i][w] = mex3(Lt[w-1][mex(f[i+1][1])],Rf[w-1][mex(f[i+1][w-1])],f[i+1][w]);
            for(int j=1;j<w-1;j++){
                f[i][j] = mex3(Lt[j-1][mex2(Lf[j+1][mex(f[i+1][j+1])],f[i-1][1])],Rt[j-1][mex2(Rf[j-1][mex(f[i+1][j-1])],f[i+1][w])],f[i+1][j]);
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i][j]=='B') ans ^= f[i][j];
        }
    }
    if(ans) cout << "Alice";
    else cout << "Bob";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5632kb

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5776kb

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

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

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

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

input:

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

output:

Bob

result:

ok "Bob"

Test #5:

score: 0
Accepted
time: 3ms
memory: 8296kb

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: 1ms
memory: 4128kb

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: 1ms
memory: 5832kb

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: 1ms
memory: 5884kb

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: 3ms
memory: 4904kb

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:

Alice

result:

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