QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423642 | #990. Colorful Components | complexor | WA | 0ms | 3840kb | C++14 | 2.7kb | 2024-05-28 14:13:30 | 2024-05-28 14:13:30 |
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3840kb
input:
5 3 1 1 3 1 5
output:
1: 1 5 2: 0 25 3: 0 125 4: 999999991 305 5: 195 0 125
result:
wrong answer 1st words differ - expected: '125', found: '1:'