QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#370905#6344. The Best Problem of 2021ucup-team1525WA 1ms3936kbC++204.0kb2024-03-29 19:05:452024-03-29 19:05:47

Judging History

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

  • [2024-03-29 19:05:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3936kb
  • [2024-03-29 19:05:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e3;
const int mod=998244353,iv2=(mod+1)/2;
int add(int x,int y){ return (x+=y)>=mod?x-mod:x; }
int sub(int x,int y){ return (x-=y)<0?x+mod:x; }
int ksm(ll x,int tp,int s=1){
    for(;tp;x=x*x%mod,tp>>=1) if(tp&1) s=x*s%mod;
    return s;
}
int n,m;
char s[N+5];
bitset<N+5> b[N+5],X,Y;
void output(bitset<N+5> x){
    for(int j=0;j<m;j++)
        printf(x[j]?"1":"0");
    puts("");
}
void insert(){
    bitset<N+5> tmp;
    tmp.reset();
    for(int j=0;j<m;j++) tmp[j]=s[j]-'0';
    // output(tmp);
    for(int i=0;i<m;i++)
        if(tmp[i]){
            if(b[i][i])
                tmp^=b[i];
            else{
                b[i]=tmp;
                return;
            }
        }
}
bool cmp(bitset<N+5> &X,bitset<N+5> &Y){
    for(int i=0;i<m;i++){
        if(X[i]<Y[i]) return 0;
        if(X[i]>Y[i]) return 1;
    }
    return 1;
}
void getY(){
    bitset<N+5> tmp;
    tmp.reset();
    for(int i=0,j=0;i<m;i++)
        if(b[i][i]){
            tmp^=b[i];
            if(cmp(X,tmp))
                Y.set(j);
            else
                tmp^=b[i];
            j++;
        }
    // puts("Y:");
    // output(Y);
    // puts("");
}
int C[N+5][N+5];
int kp[N+5],kkp[N+5];
int c[N+5];
int f[N+5][N+5],g[N+5][N+5],h[N+5][N+5];
void solve(){
    kp[0]=kkp[0]=1;
    for(int i=1;i<=n;i++){
        kp[i]=add(kp[i-1],kp[i-1]);
        kkp[i]=2*kkp[i-1]%(mod-1);
    }
    for(int i=0;i<=n;i++)
        kkp[i]=ksm(2,kkp[i]);
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=i;j++){
            C[i][j]=(1ll*C[i-1][j]*kp[j]+C[i-1][j-1])%mod;
            // printf("%d ",C[i][j]);
        }
        // puts("");
    }
    c[n]=1;
    for(int i=n-1;i>=0;i--){
        c[i]=0;
        for(int j=i+1;j<=n;j++){
            c[i]=(c[i]-1ll*c[j]*C[n-i][j-i])%mod;
        }
        if(c[i]<0) c[i]+=mod;
        // printf("%d ",c[i]);
    }
    // puts("\n");
    for(int j=0;j<n;j++){
        g[1][j]=c[j];
        f[1][j]=1ll*c[j+1]*kkp[j]%mod*kp[n-1-j]%mod;
        h[1][j]=1ll*c[j+1]*kp[n-1-j]%mod;
    }
    for(int i=1;i<n;i++){
        // for(int j=0;j<=n-i;j++)
        //     printf("%d ",f[i][j]);
        // puts("");
        if(Y[i]){
            for(int j=0;j<=n-i;j++){
                g[i+1][j]=add(g[i+1][j],g[i][j]);
                if(j)
                    g[i+1][j-1]=(g[i+1][j-1]+1ll*g[i][j]*kkp[j-1]%mod*kp[n-i-j])%mod;
                g[i+1][j]=(g[i+1][j]+1ll*f[i][j]*iv2)%mod;
                f[i+1][j]=(f[i+1][j]+1ll*f[i][j]*iv2)%mod;
                if(j){
                    f[i+1][j-1]=(f[i+1][j-1]+1ll*f[i][j]*kkp[j-1]%mod*kp[n-i-j])%mod;
                    h[i+1][j-1]=(h[i+1][j-1]+1ll*f[i][j]*kp[n-i-j])%mod;
                }
                h[i+1][j]=(h[i+1][j]+1ll*h[i][j]*iv2)%mod;
            }
        }
        else{
            for(int j=0;j<=n-i;j++){
                g[i+1][j]=add(g[i+1][j],g[i][j]);
                if(j)
                    g[i+1][j-1]=(g[i+1][j-1]+1ll*g[i][j]*kkp[j-1]%mod*kp[n-i-j])%mod;
                f[i+1][j]=(f[i+1][j]+1ll*f[i][j]*iv2)%mod;
                if(j)
                    f[i+1][j-1]=(f[i+1][j-1]+1ll*f[i][j]*kp[n-i-j])%mod;
                g[i+1][j]=(g[i+1][j]+1ll*h[i][j]*iv2)%mod;
            }
        }
    }
    printf("%d\n",add(f[n][0],g[n][0]));
}
int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%s",s);
        insert();
    }
    scanf("%s",s);
    for(int j=0;j<m;j++)
        X[j]=s[j]-'0';
    int c=0;
    for(int i=0;i<m;i++)
        if(b[i][i]){
            c++;
            for(int j=0;j<i;j++)
                if(b[j][i])
                    b[j]^=b[i];
        }
    if(c<n){
        puts("0");
        return 0;
    }
    getY();
    if(!Y[0]){
        puts("0");
        return 0;
    }
    // for(int i=0;i<m;i++)
    //     if(b[i][i])
    //         output(b[i]);
    // printf("");
    solve();
    return 0;
}

详细

Test #1:

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

input:

4 4
0001
0010
0100
1000
1101

output:

7364

result:

ok 1 number(s): "7364"

Test #2:

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

input:

3 2
00
00
00
11

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 3
110
101
101

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

3 10
1111100110
0011110100
0101100001
1110000001

output:

38

result:

ok 1 number(s): "38"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3864kb

input:

7 13
1000101001000
1000000010000
1010101011111
1001100100111
1111111101100
0101010101110
1101100010100
1000010011001

output:

197575353

result:

wrong answer 1st numbers differ - expected: '744450298', found: '197575353'