QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#64218#990. Colorful Componentsfeecle6418#WA 147ms4308kbC++141.3kb2022-11-24 12:16:342022-11-24 12:16:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-24 12:16:35]
  • 评测
  • 测评结果:WA
  • 用时:147ms
  • 内存:4308kb
  • [2022-11-24 12:16:34]
  • 提交

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(k-j,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: 0ms
memory: 4148kb

input:

5 3
1
1
3
1
5

output:

125

result:

ok "125"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3984kb

input:

4 2
2
1
1
1

output:

7

result:

ok "7"

Test #3:

score: -100
Wrong Answer
time: 147ms
memory: 4308kb

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:

799174250

result:

wrong answer 1st words differ - expected: '540253743', found: '799174250'