QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235515#1811. How to Move the Beansyx20220802TL 0ms0kbC++143.3kb2023-11-02 21:04:102023-11-02 21:04:11

Judging History

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

  • [2023-11-02 21:04:11]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-11-02 21:04:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO_ER{
    #define LL long long
    #define db double
    #define U unsigned
    #define ULL U LL
    #define In inline
    #define Re register
    #define f(a,b,i) for(int i=a;i<=b;i++)
    #define ff(a,b,i) for(int i=a;i<b;i++)
    #define f_(a,b,i) for(int i=a;i>=b;i--)
    #define ff_(a,b,i) for(int i=a;i>b;i--)
    typedef pair<LL,int> Pi;
    int inf=0x3f3f3f3f;
    int INF=0x7fffffff;
    LL infll=0x3f3f3f3f3f3f3f3fll;
    LL INFll=0x7fffffffffffffffll;
    template<typename T>void read(T &x){
        x=0;
        int fl=0;
        char ch=getchar();
        while(ch<'0'||'9'<ch){
            if(ch=='-')fl=1;
            ch=getchar();
        }
        while('0'<=ch&&ch<='9'){
            x=(x<<1)+(x<<3)+(ch^48);
            ch=getchar();
        }
        x=fl?-x:x;
    }
    template<typename T,typename ...Args>void read(T &x,Args &...args){
        read(x);
        read(args...);
    }
}
using namespace IO_ER;

#define N 1050

int n,m;

char ch[N][N];

int L[N];
int R[N];

In int mex(int x,int y=3,int z=3){
    int cnt[4]={0,0,0,0};
    cnt[x]++;
    cnt[y]++;
    cnt[z]++;
    if(!cnt[0])return 0;
    if(!cnt[1])return 1;
    if(!cnt[2])return 2;
    return 3;
}

int sg[N][N];

int pre[N];
int nxt[N];

int pr1[N][3];
int pr2[N][3];
int sf1[N][3];
int sf2[N][3];

In void sol(){
    read(n,m);
    f(1,n,i)scanf("%s",ch[i]+1);
    f(1,m,j)sg[n+1][j]=3;
    f(1,m,i)pre[i]=i-1,nxt[i]=i+1;
    pre[1]=m;
    nxt[m]=1;
    f_(n,1,i){
        int fl=0;
        f(1,m,j)fl|=(ch[i][j]=='#');
        if(fl){
            f(1,m,j)L[j]=R[j]=3;
            for(int j=1;L[j]==3;j=nxt[j]){
                if(ch[i][j]=='#')L[j]=0;
                else L[j]=mex(L[pre[j]],sg[i+1][j]);
            }
            for(int j=m;R[j]==3;j=pre[j]){
                if(ch[i][j]=='#')R[j]=0;
                else R[j]=mex(R[nxt[j]],sg[i+1][j]);
            }
            f(1,m,j){
                if(ch[i][j]=='#')sg[i][j]=3;
                else sg[i][j]=mex(sg[i+1][j],L[pre[j]],R[nxt[j]]);
            }
        }
        else{
            if(m==1){
                sg[i][1]=mex(sg[i+1][1]);
                continue;
            }
            f(2,m,j){
                f(0,2,k){
                    pr1[j][k]=mex(pr1[j-1][k],sg[i+1][j]);
                    pr2[j][k]=pr2[j-1][mex(k,sg[i+1][j-1])];
                }
            }
            f(1,m-1,j){
                f(0,2,k){
                    sf1[j][k]=mex(sf1[j+1][k],sg[i+1][j]);
                    sf2[j][k]=sf2[j+1][mex(k,sg[i+1][j+1])];
                }
            }
            sg[i][0]=mex(sg[i+1][0],sf1[1][mex(sg[i+1][m-1])],sf2[1][mex(sg[i+1][1])]);
            sg[i][m-1]=mex(sg[i+1][m-1],pr1[m-2][mex(sg[i+1][0])],pr2[m-2][mex(sg[i+1][m-2])]);
            f(2,m-1,j){
                sg[i][j]=mex(sg[i+1][j],pr1[j-1][mex(sg[i+1][0],sf2[j+1][mex(sg[i+1][j+1])])],sf1[j+1][mex(sg[i+1][m-1],pr2[j-1][mex(sg[i+1][j-1])])]);
            }
        }
    }
    int ans=0;
    f(1,n,i){
        f(1,m,j){
            if(ch[i][j]=='B')ans^=sg[i][j];
        }
    }
    puts(ans?"A":"B");
}

int main(){
    int Ti;
    read(Ti);
    while(Ti--)sol();
    return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

2 3
B.#
#..

output:


result: