QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84831#990. Colorful ComponentsMinionWA 1ms1736kbC++141.1kb2023-03-06 20:02:092023-03-06 20:02:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 20:02:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:1736kb
  • [2023-03-06 20:02:09]
  • 提交

answer

#include<cstdio>
#define fo(i,x,y) for(int i = x;i <= y;++i)
#define fd(i,x,y) for(int i = x;i >= y;--i)
#define p 1000000007
int n,m,x,c[310],iv[310],f[310],ef[310],w[310],ifac[310],fac[310];
int ksm(int x,int y)
{
	int res = 1;
	for(;y;y >>= 1,x = 1ll * x * x % p) if(y & 1) res = 1ll * res * x % p;
	return res;
}
int main()
{
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%d",&x),++c[x];
	fac[0] = 1;
	fo(i,1,n) fac[i] = 1ll * fac[i - 1] * i % p;
	ifac[n] = ksm(fac[n],p - 2);
	fd(i,n - 1,0) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % p,iv[i] = 1ll * ifac[i] * fac[i - 1] % p;
	fo(i,1,m) w[i] = 1ll * ksm(i,i - 1) * ifac[i] % p;
	int ans = 1;
	fo(i,1,n) if(c[i])
	{
		int C = c[i];
		fo(j,1,C) f[j] = (j <= m) ? 1ll * (n - C) * w[j] % p : 0;
		ef[0] = 1;
		fo(j,1,C)
		{
			fo(k,0,j - 1) ef[j] = (ef[j] + 1ll * ef[k] * f[j - k] % p * (j - k)) % p;
			ef[j] = 1ll * ef[j] * iv[j] % p;
		}
		int res = 0;
		fo(j,1,C) res = (res + 1ll * j * w[j] % p * n % p * ef[C - j]) % p;
		ans = 1ll * ans * res % p * fac[C - 1] % p;
	}
	printf("%lld\n",1ll * ans * ksm(n,(p - 2) * 2) % p);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 1736kb

input:

5 3
1
1
3
1
5

output:

125

result:

ok "125"

Test #2:

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

input:

4 2
2
1
1
1

output:

7

result:

ok "7"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 1692kb

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:

196582840

result:

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