QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424075 | #990. Colorful Components | chenyitaoooo | WA | 0ms | 3828kb | C++14 | 1.1kb | 2024-05-28 21:29:03 | 2024-05-28 21:29:04 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define Ri register LL
using namespace std;
const int N=315;
const LL mo=1e9+7;
LL f[N],g[N],K,ans=1,n,c[N],C[N][N],h[N][N];
LL ksm(LL x,LL y){
LL res=1;
while(y>0){
if(y&1) res=res*x%mo;
x=x*x%mo;
y>>=1;
}
return res;
}
int main(){
scanf("%lld %lld",&n,&K);
for(Ri i=1; i<=n; ++i){
int x;
scanf("%d",&x),c[x]++;
}
for(Ri i=0; i<=n; ++i) C[i][0]=1;
for(Ri i=1; i<=n; ++i){
for(Ri j=1; j<=i; ++j) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
}
h[0][0]=1;
for(Ri i=1; i<=n; ++i){
for(Ri j=1; j<=i; ++j){
for(Ri k=1; k<=min(i,K); ++k) h[i][j]+=h[i-k][j-1]*k%mo*C[i-1][k-1]%mo;
h[i][j]%=mo;
}
LL o=1;
for(Ri j=1; j<=i; ++j){
o=o*i%mo;
if(j&1) g[i]+=h[i][j]*o%mo;
else g[i]-=h[i][j]*o%mo;
}
g[i]=(g[i]%mo*ksm(i,mo-3))%mo;
}
for(Ri i=1; i<=n; ++i) g[i]=g[i]*i%mo*n%mo;
f[0]=1;
for(Ri i=1; i<=n; ++i){
for(Ri j=1; j<=i; ++j) f[i]+=f[i-j]*g[j]%mo*C[i-1][j-1]%mo;
f[i]%=mo;
}
// for(Ri i=1; i<=n; ++i) printf("%lld ",f[i]);
for(Ri i=1; i<=n; ++i) ans*=f[c[i]]%mo;
printf("%lld\n",(ans*ksm(n,mo-3)%mo+mo)%mo);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3828kb
input:
5 3 1 1 3 1 5
output:
95
result:
wrong answer 1st words differ - expected: '125', found: '95'