QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569150#9317. RivalsTomato_FishTL 2759ms38344kbC++142.9kb2024-09-16 20:52:122024-09-16 20:52:12

Judging History

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

  • [2024-09-16 20:52:12]
  • 评测
  • 测评结果:TL
  • 用时:2759ms
  • 内存:38344kb
  • [2024-09-16 20:52:12]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=(1<<20)+100,M=12,mod=998244353;
int Mi[M],cnt[M],p[M],h[N],w[N][M],g[N];

bool cmp(int n1,int n2) {return (g[n1]<g[n2]);}

int mi(int x,int t){
    int d=1;
    while(t){
        if(t%2) d=(ll)d*x%mod;
        x=(ll)x*x%mod;t/=2;
    }
    return d;
}
int ni(int x) {return mi(x,mod-2);}

const int maxn=300;
int f[N],res[N],C[310][310],ff[N],fl[310],Res[N],a[N];

int main()
{

    int n,c;
    scanf("%d%d",&n,&c);

    fl[0]=1;for(int i=1;i<=maxn;i++) fl[i]=(ll)fl[i-1]*i%mod;

    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        if(i<=c) p[x]++;
        cnt[x]++;
    }

    Mi[0]=1;
    for(int i=1;i<=10;i++) Mi[i]=Mi[i-1]*(cnt[i]+1);

    for(int i=0;i<Mi[10];i++){
        int e=i;
        for(int j=1;j<=10;j++){
            w[i][j]=e%(cnt[j]+1);
            e/=(cnt[j]+1);
            g[i]=g[i]+j*w[i][j];
            res[i]=res[i]+(cnt[j]-w[i][j]);
        }
        h[i]=i;
    }
    sort(h,h+Mi[10],cmp);

    for(int i=0;i<Mi[10];i++) Res[i]=res[i],res[i]=ni(res[i]);
    for(int i=0;i<=maxn;i++) C[i][0]=C[i][i]=1;
    for(int i=2;i<=maxn;i++)
        for(int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;

    // printf("???\n");
    ff[Mi[10]-1]=1;
    for(int i=g[Mi[10]-1];i>=1;i--){
        for(int j=0;j<Mi[10];j++){
            int Sum=0;
            if(i-g[h[j]]-1>=0){
                for(int k=1;k<=10;k++)
                    if(w[h[j]][k]<cnt[k]) Sum=(Sum+(ll)ff[h[j]+Mi[k-1]]*C[i-g[h[j]]-1][k-1])%mod;
            }
            ff[h[j]]=(ll)(ff[h[j]]+Sum)*res[h[j]]%mod;
        }
    }
    // for(int i=0;i<Mi[10];i++) printf("%d %d\n",i,ff[i]);

    for(int i=0;i<Mi[10];i++){
        a[i]=1;
        for(int j=1;j<=10;j++)
            a[i]=(ll)a[i]*C[w[i][j]][p[j]]%mod*fl[p[j]]%mod;
    }
    int D=1;
    for(int i=1;i<=10;i++) D=(ll)D*fl[cnt[i]-p[i]]%mod;

    // return 0;

    // printf("%d\n",Mi[10]);
    f[0]=1;
    for(int i=1;i<=g[Mi[10]-1];i++){
        for(int j=Mi[10]-1;j>=0;j--){
            if(g[h[j]]<=i){
                f[h[j]]=(ll)f[h[j]]*res[h[j]]%mod;
                for(int k=1;k<=10;k++){
                    if(w[h[j]][k]<cnt[k]) f[h[j]+Mi[k-1]]=(f[h[j]+Mi[k-1]]+(ll)f[h[j]]*C[i-g[h[j]]-1][k-1])%mod;
                }
            }
            ff[h[j]]=(ll)ff[h[j]]*Res[h[j]]%mod;
            if(i-g[h[j]]-1>=0){
                for(int k=1;k<=10;k++)
                    if(w[h[j]][k]<cnt[k]) ff[h[j]]=(ff[h[j]]-(ll)ff[h[j]+Mi[k-1]]*C[i-g[h[j]]-1][k-1]%mod+mod)%mod;
            }
        }

        if(i==g[Mi[10]-1]) printf("1 ");
        else{
            int Ans=0;
            for(int j=0;j<Mi[10];j++){
                if(g[h[j]]>i) break;
                Ans=(Ans+(ll)f[h[j]]*ff[h[j]]%mod*a[h[j]]%mod*D)%mod;
            }
            printf("%d ",Ans);
        }
    }
    printf("\n");

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 3
1 1 1 1 1

output:

0 0 299473306 199648871 1 

result:

ok 5 tokens

Test #2:

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

input:

8 5
3 5 3 2 2 5 4 4

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 851829480 293319617 603094447 451112091 433952646 112377604 425219038 332689344 62257787 407546627 163509571 467949711 235335868 1 

result:

ok 28 tokens

Test #3:

score: 0
Accepted
time: 2759ms
memory: 38344kb

input:

30 17
1 8 9 3 2 6 6 9 5 9 1 2 1 3 3 1 1 5 7 1 2 5 5 7 3 3 4 7 5 6

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 447486792 435664782 192289330 927851817 610835375 240199921 954404690 368032120 126246490 646683498 959653535 111169893 486702262 177564172 129608751 316471586 15...

result:

ok 130 tokens

Test #4:

score: -100
Time Limit Exceeded

input:

30 30
10 6 2 10 9 8 7 7 6 3 2 10 3 1 7 3 10 5 7 8 1 2 6 9 4 10 7 2 4 6

output:


result: