QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233590#1811. How to Move the Beanssumi007WA 3ms7896kbC++143.1kb2023-10-31 20:04:352023-10-31 20:04:35

Judging History

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

  • [2023-10-31 20:04:35]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7896kb
  • [2023-10-31 20:04:35]
  • 提交

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=2;j<w;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: 0ms
memory: 3676kb

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

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

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

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

input:

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

output:

Bob

result:

ok "Bob"

Test #5:

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

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: 7676kb

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'