QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88579#990. Colorful ComponentsxiaoyaowudiWA 27ms3928kbC++141.4kb2023-03-16 16:03:562023-03-16 16:04:00

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-16 16:04:00]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3928kb
  • [2023-03-16 16:03:56]
  • 提交

answer

#include <algorithm>
#include <iostream>
constexpr int p(1e9+7),N(310);
int f[N][N],cnt[N],g[N],t[N],ifac[N],fac[N],inv[N];
int binom(int a,int b){return 1ll*fac[a]*ifac[b]%p*ifac[a-b]%p;}
int fp(int a,int b){int ans(1),off(a);while(b){if(b&1) ans=1ll*ans*off%p;off=1ll*off*off%p;b>>=1;}return ans;}
int main()
{
	int n,k;std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
	std::cin>>n>>k;for(int i(1),t;i<=n;++i) std::cin>>t,++cnt[t];
	int m(0);for(int i(1);i<=n;++i) m=std::max(m,cnt[i]);
	f[0][0]=1;
	inv[1]=1;for(int i(2);i<N;++i) inv[i]=1ll*(p-p/i)*inv[p%i]%p;
	fac[0]=ifac[0]=1;for(int i(1);i<N;++i) fac[i]=1ll*fac[i-1]*i%p,ifac[i]=1ll*ifac[i-1]*inv[i]%p;
	for(int i(1);i<=m;++i)
	{
		int cur(0);
		for(int j(2),l(1);j<=i;++j,l=1ll*l*i%p)
		{
			for(int k(1);i-k>=j-1;++k)
			{
				f[i][j]=(f[i][j]+1ll*f[i-k][j-1]*t[k]%p*binom(i-1,k-1))%p;
			}
			cur=(cur+1ll*f[i][j]*l)%p;
		}
		g[i]=(i<=k)?(i==1?1:fp(i,i-2)):0;
		g[i]=(g[i]-cur+p)%p;
		t[i]=1ll*g[i]*i%p;f[i][1]=t[i];
	}
	static int r[N];r[0]=1;
	for(int i(1),tot(0);i<=n;++i) if(cnt[i])
	{
		for(int j(tot+cnt[i]);j>=0;--j)
		{
			int cur(0);
			for(int k(0);k<=cnt[i] && k<=j;++k) cur=(cur+1ll*r[j-k]*f[cnt[i]][k])%p;
			r[j]=cur;
		}
		tot+=cnt[i];
	}
	int ans(r[1]);
	for(int i(2),j(1);i<=n;j=1ll*j*n%p,++i) ans=(ans+1ll*j*r[i])%p;
	std::cout<<ans<<std::endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3552kb

input:

5 3
1
1
3
1
5

output:

125

result:

ok "125"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3440kb

input:

4 2
2
1
1
1

output:

7

result:

ok "7"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3424kb

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:

540253743

result:

ok "540253743"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

300 20
2
7
4
5
1
10
3
10
9
2
6
4
9
4
5
2
6
10
9
8
4
10
8
5
5
1
3
1
1
7
5
5
3
8
7
10
2
3
2
7
4
7
7
7
9
9
2
7
9
6
3
3
4
1
8
8
4
3
4
8
5
10
9
3
3
6
7
6
7
10
7
2
9
3
3
10
3
7
4
8
10
1
4
5
10
2
3
7
3
4
9
5
10
5
10
9
5
3
2
9
4
4
3
10
3
6
1
8
5
10
4
5
7
10
5
5
7
2
7
3
1
5
4
1
9
3
5
1
9
4
7
10
2
2
4
10
8
9
...

output:

616258392

result:

ok "616258392"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3312kb

input:

300 1
124
25
131
70
63
150
139
62
46
94
9
34
25
102
66
120
139
28
134
120
98
135
95
21
43
71
11
87
45
15
33
58
37
70
12
63
132
47
104
97
67
17
9
119
72
87
29
96
53
103
34
71
58
78
34
3
94
78
115
60
139
43
63
46
127
146
37
60
37
12
59
23
43
120
53
107
54
68
70
21
94
125
10
22
143
117
133
64
129
55
14...

output:

450350134

result:

ok "450350134"

Test #6:

score: 0
Accepted
time: 2ms
memory: 3440kb

input:

300 2
131
70
63
150
139
62
46
94
9
34
25
102
66
120
139
28
134
120
98
135
95
21
43
71
11
87
45
15
33
58
37
70
12
63
132
47
104
97
67
17
9
119
72
87
29
96
53
103
34
71
58
78
34
3
94
78
115
60
139
43
63
46
127
146
37
60
37
12
59
23
43
120
53
107
54
68
70
21
94
125
10
22
143
117
133
64
129
55
140
75
10...

output:

942808207

result:

ok "942808207"

Test #7:

score: 0
Accepted
time: 10ms
memory: 3700kb

input:

300 150
1
2
2
2
1
2
1
2
2
2
1
2
2
2
2
1
1
1
1
1
1
1
1
1
1
2
1
2
2
1
2
1
2
1
1
1
1
1
2
1
1
2
1
1
2
1
2
2
2
1
2
2
1
2
1
1
1
2
1
2
1
2
1
2
1
1
1
2
1
1
2
2
2
1
2
1
2
2
1
1
1
2
1
1
2
1
2
1
1
1
2
1
2
2
1
2
1
2
1
2
1
2
2
1
1
2
1
1
1
2
1
1
1
1
2
1
1
1
1
1
1
2
1
2
2
2
2
2
2
1
1
1
2
2
1
1
1
1
1
2
1
1
2
1
1
1
...

output:

169425341

result:

ok "169425341"

Test #8:

score: 0
Accepted
time: 7ms
memory: 3508kb

input:

300 290
2
2
1
2
1
2
2
2
1
2
2
2
2
1
1
1
1
1
1
1
1
1
1
2
1
2
2
1
2
1
2
1
1
1
1
1
2
1
1
2
1
1
2
1
2
2
2
1
2
2
1
2
1
1
1
2
1
2
1
2
1
2
1
1
1
2
1
1
2
2
2
1
2
1
2
2
1
1
1
2
1
1
2
1
2
1
1
1
2
1
2
2
1
2
1
2
1
2
1
2
2
1
1
2
1
1
1
2
1
1
1
1
2
1
1
1
1
1
1
2
1
2
2
2
2
2
2
1
1
1
2
2
1
1
1
1
1
2
1
1
2
1
1
1
1
2
...

output:

394671363

result:

ok "394671363"

Test #9:

score: -100
Wrong Answer
time: 27ms
memory: 3928kb

input:

300 290
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

output:

976730434

result:

wrong answer 1st words differ - expected: '0', found: '976730434'