QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64219 | #990. Colorful Components | feecle6418# | WA | 196ms | 4488kb | C++14 | 1.3kb | 2022-11-24 12:19:03 | 2022-11-24 12:19:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,K,a[305],f[305][305],ff[305][305],h[305][305],v1[305],jc[305],ny[305];
int C(int x,int y){
if(x<y||y<0||x<0)return 0;
return 1ll*jc[x]*ny[y]%mod*ny[x-y]%mod;
}
int Power(int x,int y){
if(y<0)return Power(Power(x,mod-2),-y);
int r=1;
while(y){
if(y&1)r=1ll*r*x%mod;
x=1ll*x*x%mod,y>>=1;
}
return r;
}
int main(){
cin>>n>>K;
ny[0]=jc[0]=1;
for(int i=1;i<=n;i++)jc[i]=1ll*jc[i-1]*i%mod;
ny[n]=Power(jc[n],mod-2);
for(int i=n-1;i;i--)ny[i]=1ll*ny[i+1]*(i+1)%mod;
for(int i=1,x;i<=n;i++)cin>>x,a[x]++;
h[0][0]=1;
for(int i=1;i<=n;i++)v1[i]=1ll*ny[i]*Power(i,i-2)%mod*i%mod;
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
for(int k=1;k<=K;k++){
h[i][j]=(h[i][j]+1ll*h[i-k][j-1]*v1[k])%mod;
}
}
}
for(int i=1;i<=n;i++)for(int j=1;j<=i;j++)h[i][j]=1ll*h[i][j]*jc[i]%mod*ny[j]%mod;
for(int i=1;i<=n;i++)f[i][0]=1;
int m=0;
for(int i=1;i<=n;i++){
if(!a[i])continue;
m++;
for(int j=1;j<=a[i];j++){
for(int k=j;k<=n;k++){
for(int l=j;l<=k;l++){
ff[k][l]=(ff[k][l]+1ll*f[k][l-j]*h[a[i]][j]%mod*Power(n-a[i],j-1))%mod;
}
}
}
memcpy(f,ff,sizeof(f));
memset(ff,0,sizeof(ff));
}
int ans=0;
for(int i=1;i<=n;i++)ans=(ans+1ll*f[i][i]*Power(n,m-2))%mod;
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 4024kb
input:
5 3 1 1 3 1 5
output:
125
result:
ok "125"
Test #2:
score: 0
Accepted
time: 2ms
memory: 4080kb
input:
4 2 2 1 1 1
output:
7
result:
ok "7"
Test #3:
score: -100
Wrong Answer
time: 196ms
memory: 4488kb
input:
300 16 2 2 2 4 5 1 5 3 5 4 2 1 4 4 4 5 2 1 5 4 3 4 5 3 5 5 1 3 1 1 2 5 5 3 3 2 5 2 3 2 2 4 2 2 2 4 4 2 2 4 1 3 3 4 1 3 3 4 3 4 3 5 5 4 3 3 1 2 1 2 5 2 2 4 3 3 5 3 2 4 3 5 1 4 5 5 2 3 2 3 4 4 5 5 5 5 4 5 3 2 4 4 4 3 5 3 1 1 3 5 5 4 5 2 5 5 5 2 2 2 3 1 5 4 1 4 3 5 1 4 4 2 5 2 2 4 5 3 4 3 3 4 2 5 1 1 3...
output:
124578246
result:
wrong answer 1st words differ - expected: '540253743', found: '124578246'