QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#423643 | #990. Colorful Components | complexor | WA | 25ms | 4612kb | C++14 | 2.7kb | 2024-05-28 14:13:50 | 2024-05-28 14:13:51 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long LL;
typedef std::pair<int, int> pii;
typedef std::pair<LL, LL> pll;
typedef std::pair<LL, int> pli;
#define MP std::make_pair
#define fi first
#define se second
int read()
{
int s = 0, f = 1;
char c = getchar();
while (!(c >= '0' && c <= '9'))
f ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9')
s = s * 10 + (c ^ 48), c = getchar();
return f ? s : -s;
}
const int MAXN = 305, MOD = 1e9 + 7, inf = 0x3f3f3f3f, MAXM = 105, MAXV = 55;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
auto fplus = [](int x, int y){ return x + y >= MOD ? x + y - MOD : x + y; };
auto fminus = [](int x, int y){ return x >= y ? x - y : x + MOD - y; };
auto Fplus = [](int &x, int y){ return x = fplus(x, y); };
auto Fminus = [](int &x, int y){ return x = fminus(x, y); };
template<typename T>
T& Fmin(T &x, T y){ return x = x < y ? x : y; };
template<typename T>
T& Fmax(T &x, T y){ return x = x > y ? x : y; };
int fpow(int x, int y = MOD - 2)
{
int res = 1;
for (; y; y >>= 1, x = (LL)x * x % MOD)
if (y & 1) res = (LL)res * x % MOD;
return res;
}
int n, K, cnt[MAXN], comb[MAXN][MAXN], f[MAXN], g[MAXN], dp[MAXN][MAXN], h[MAXN];
int main()
{
n = read(), K = read();
for (int i = 1; i <= n; i++) cnt[read()]++;
for (int i = 1; i <= n; i++)
if (cnt[i] == n) return printf("%d\n", fpow(n, n - 2)), 0;
for (int i = 0; i <= n; i++) comb[i][0] = 1;
for (int i = 2; i <= n; i++) h[i] = fpow(i, i - 2);
h[1] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
comb[i][j] = fplus(comb[i - 1][j - 1], comb[i - 1][j]);
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 0; j < i; j++)
for (int s = 1; s + j <= i && s <= K; s++)
dp[i][j + 1] = (dp[i][j + 1] + (LL)dp[i - s][j] * comb[i - 1][s - 1] % MOD * s % MOD * h[s]) % MOD;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
{
// printf("dp %d %d: %d\n", i, j, dp[i][j]);
int v = (LL)dp[i][j] * fpow(i, std::max(0, j - 2)) % MOD;
if (j == 1) v = (LL)v * fpow(i) % MOD;
((j & 1) ? Fplus : Fminus)(f[i], v);
}
g[0] = 1;
for (int i = 1; i <= n; i++)
for (int s = 1; s <= i; s++)
g[i] = (g[i] + (LL)g[i - s] * comb[i - 1][s - 1] % MOD * f[s] % MOD * n % MOD * s) % MOD;//, printf("%d %d: %d\n", i, s, g[i]);
// for (int i = 1; i <= n; i++) printf("%d: %d %d\n", i, f[i], g[i]);
int ans = fpow(n, MOD - 1 - 2);
for (int i = 1; i <= n; i++)
ans = (LL)ans * g[cnt[i]] % MOD;
printf("%d\n", ans);
return 0;
}
/*
5 3
1
1
3
1
5
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3760kb
input:
5 3 1 1 3 1 5
output:
125
result:
ok "125"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
4 2 2 1 1 1
output:
7
result:
ok "7"
Test #3:
score: 0
Accepted
time: 5ms
memory: 4612kb
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: 6ms
memory: 4404kb
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: 2ms
memory: 4484kb
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: 4460kb
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: 22ms
memory: 4612kb
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: 25ms
memory: 4552kb
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: 0ms
memory: 3800kb
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:
394671363
result:
wrong answer 1st words differ - expected: '0', found: '394671363'