QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#235258#1811. How to Move the Beans11d10xyWA 3ms8848kbC++142.0kb2023-11-02 16:30:472023-11-02 16:30:47

Judging History

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

  • [2023-11-02 16:30:47]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8848kb
  • [2023-11-02 16:30:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char mp[1010][1010];
int n,m,SG[1010][1010];
struct node_t{
    int res[3];
    node_t operator+(const node_t&o)const{return{{o.res[res[0]],o.res[res[1]],o.res[res[2]]}};}
};
const node_t I={{0,1,2}};
void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
    for(int i=n;i;i--){
        vector<int>mask(m+5);
        vector<node_t>trans(m+5,I);
        for(int j=1;j<=m;j++)
        if(mp[i][j]=='#')trans[j]={{2,2,2}};
        else if(i==n||SG[i+1][j]>=2)trans[j]={{1,0,0}};
        else if(SG[i+1][j]==1)trans[j]={{2,0,0}};
        else trans[j]={{1,2,1}};
        int pos=m;while(pos&&mp[i][pos]!='#')pos--;
        if(!pos){
            vector<node_t>pre(m+5,I),suf(m+5,I);
            for(int j=1;j<=m;j++)pre[j]=trans[j]+pre[j-1];
            for(int j=m;j;j--)suf[j]=suf[j+1]+trans[j];
            for(int j=1;j<=m;j++)
            mask[j]|=1<<(pre[j-1]+suf[j+1]).res[2];
            for(int j=1;j<=m;j++)pre[j]=pre[j-1]+trans[j];
            for(int j=m;j;j--)suf[j]=trans[j]+suf[j+1];
            for(int j=1;j<=m;j++)
            mask[j]|=1<<(suf[j+1]+pre[j-1]).res[2];
        }else{
            vector<int>slc;
            for(int j=pos+1;;j++){
                if(j>m)j=1;
                if(mp[i][j]=='#'){
                    int len=slc.size();
                    int a=2;
                    for(int k=0;k<len;k++)
                    mask[slc[k]]|=1<<a,a=trans[slc[k]].res[a];
                    a=2; 
                    for(int k=len-1;k>=0;k--)
                    mask[slc[k]]|=1<<a,a=trans[slc[k]].res[a];
                    slc.clear();
                }else slc.push_back(j);
                if(j==pos)break;
            }
        }
        for(int j=1;j<=m;j++)
        SG[i][j]=mp[i][j]=='#'?3:__builtin_ctz(~(mask[j]|1<<(i==n?17:SG[i+1][j])));
    }int ans=0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    if(mp[i][j]=='B')ans^=SG[i][j];
    puts(ans?"Alice":"Bob");
}
int main(){
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3776kb

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

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

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

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

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

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

input:

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

output:

Bob

result:

ok "Bob"

Test #5:

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

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

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

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

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: 2ms
memory: 5172kb

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'