QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602106 | #990. Colorful Components | Made_in_Code | WA | 25ms | 5064kb | C++14 | 2.4kb | 2024-09-30 19:37:47 | 2024-09-30 19:37:47 |
Judging History
answer
#include <iostream>
#define LL long long
using namespace std;
const int kMaxN = 301, kMod = 1e9 + 7;
// const int kMaxN = 5, kMod = 1e9 + 7;
int n, m, p, a[kMaxN];
LL ans, pw[kMaxN], f[kMaxN][kMaxN], g[kMaxN][kMaxN], h[kMaxN][kMaxN];
LL fact[kMaxN], _fact[kMaxN];
LL Pow(LL x, int y = kMod - 2) {
LL ans = 1;
y = (y + kMod - 1) % (kMod - 1);
for (int i = 1; i <= y; i <<= 1) {
if (i & y) {
ans = ans * x % kMod;
}
x = x * x % kMod;
}
return ans;
}
LL C(int x, int y) { return fact[x] * _fact[y] % kMod * _fact[x - y] % kMod; }
void Add(LL &x, LL y) { x = (x + y) % kMod; }
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
fact[0] = 1;
for (int i = 1; i < kMaxN; i++) {
fact[i] = fact[i - 1] * i % kMod;
}
_fact[kMaxN - 1] = Pow(fact[kMaxN - 1]);
for (int i = kMaxN - 1; i >= 1; i--) {
_fact[i - 1] = _fact[i] * i % kMod;
}
cin >> n >> m;
for (int i = 1, x; i <= n; i++) {
cin >> x, a[x]++;
}
for (int i = 1; i <= m; i++) {
pw[i] = Pow(i, i - 1);
}
f[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
for (int k = 1; k <= m && i + k <= n; k++) {
Add(f[i + k][j + 1], f[i][j] * C(i + k - 1, i) % kMod * pw[k]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = f[i][j] * Pow(i, j - 2) % kMod;
// cout << f[i][j] << " \n"[j == n];
}
}
// cout << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
Add(g[i][1], j & 1 ? f[i][j] : kMod - f[i][j]);
}
g[i][1] = g[i][1] * i % kMod;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j + i <= n; j++) {
for (int k = 1; k < n; k++) {
Add(g[j + i][k + 1], g[j][k] * g[i][1]);
}
}
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// cout << g[i][j] << " \n"[j == n];
// }
// }
// cout << '\n';
h[0][0] = 1;
for (int i = 1; i <= n; i++) {
if (a[i]) {
for (int j = 1; j <= a[i]; j++) {
for (int k = 0; k <= n - j; k++) {
Add(h[i][k + j], h[p][k] * g[a[i]][j]);
}
g[a[i]][j];
}
p = i;
}
}
for (int i = 1; i <= n; i++) {
h[p][i] = h[p][i] * Pow(n, i - 2) % kMod;
Add(ans, h[p][i]);
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
5 3 1 1 3 1 5
output:
125
result:
ok "125"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
4 2 2 1 1 1
output:
7
result:
ok "7"
Test #3:
score: -100
Wrong Answer
time: 25ms
memory: 5064kb
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:
41508189
result:
wrong answer 1st words differ - expected: '540253743', found: '41508189'