QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569045 | #9317. Rivals | Tomato_Fish | TL | 2ms | 14524kb | C++14 | 2.8kb | 2024-09-16 20:08:20 | 2024-09-16 20:08:21 |
Judging History
answer
#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;
ff[Mi[10]-1]=1;
for(int i=g[Mi[10]-1];i>=1;i--){
for(int j=0;j<Mi[10];j++){
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;
}
for(int j=0;j<Mi[10];j++){
ff[h[j]]=(ll)ff[h[j]]*res[h[j]]%mod;
}
}
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;
f[0]=1;
for(int i=1;i<=g[Mi[10]-1];i++){
int lim=Mi[10]-1;
for(int j=0;j<Mi[10];j++){
if(g[h[j]]>i) {lim=j-1;break;}
f[h[j]]=(ll)f[h[j]]*res[h[j]]%mod;
}
for(int j=lim;j>=0;j--){
for(int k=1;k<=10;k++)
if(w[h[j]][k]) f[h[j]]=(f[h[j]]+(ll)f[h[j]-Mi[k-1]]*C[i-g[h[j]-Mi[k-1]]-1][k-1])%mod;
}
for(int j=Mi[10]-1;j>=0;j--){
ff[h[j]]=(ll)ff[h[j]]*Res[h[j]]%mod;
}
for(int j=Mi[10]-1;j>=0;j--){
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<=lim;j++)
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: 2ms
memory: 14524kb
input:
5 3 1 1 1 1 1
output:
0 0 299473306 199648871 1
result:
ok 5 tokens
Test #2:
score: 0
Accepted
time: 2ms
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: -100
Time Limit Exceeded
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