QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#760954 | #8942. Sugar Sweet 3 | chy_is_a_fish | AC ✓ | 968ms | 8960kb | C++14 | 2.4kb | 2024-11-18 20:21:19 | 2024-11-18 20:21:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1005, mod = 1e9 + 7;
int n, A, B, C, x, fac[N], inv[N], ifac[N], f[N][N], g[N][N], h[N], a[N], b[N], ans;
int ksm(int a, int b)
{
int ret = 1;
while (b)
{
if (b & 1) ret = 1ll * ret * a % mod;
a = 1ll * a * a % mod; b >>= 1;
}
return ret;
}
int c(int n, int m)
{
if (n < m || m < 0) return 0;
return 1ll * fac[n] * ifac[m] % mod * ifac[n-m] % mod;
}
void add(int &x, int y) {if ((x += y) >= mod) x -= mod;}
int main()
{
fac[0] = inv[0] = inv[1] = ifac[0] = 1;
for (int i = 1; i < N; i++) fac[i] = 1ll * fac[i-1] * i % mod;
for (int i = 2; i < N; i++) inv[i] = 1ll * inv[mod%i] * (mod - mod / i) % mod;
for (int i = 1; i < N; i++) ifac[i] = 1ll * ifac[i-1] * inv[i] % mod;
cin >> A >> B >> C >> x;
if (A + B + C & 1) return cout << 0, 0;
n = (A + B + C) / 2; f[0][0] = 1;
for (int i = 1; i <= n; i++) f[1][i] = 1ll * c(2 * i - 2, i - 1) * inv[i] % mod;
for (int i = 2; i <= n; i++) for (int j = i - 1; j <= n; j++)
for (int k = 1; k <= n - j; k++) add(f[i][j+k], 1ll * f[i-1][j] * f[1][k] % mod);
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++)
f[i][j] = 1ll * f[i][j] * ifac[i] % mod;
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++)
for (int k = n; k >= 0; k--) g[i][j] = (1ll * g[i][j] * j + f[k][i]) % mod;
for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++)
{
int k = n - i - j, mul = 0;
if (k < 0 || k > C) continue;
for (int o = 0; o <= C - k; o++)
{
int v = o - i - j + B, u = v - k - i + A;
if (u < 0 || u > A - i) continue;
if (v < 0 || v > B - j) continue;
add(mul, 1ll * c(i, o) * c(j, u) % mod * c(k, v) % mod);
}
for (int o = 0; o <= n; o++)
add(h[o], 1ll * g[i][o] * g[j][o] % mod * g[k][o] % mod * mul % mod);
}
for (int i = 0; i <= n; i++)
{
h[i] = 1ll * h[i] * ifac[i] % mod * ifac[n-i] % mod;
if ((n ^ i) & 1) h[i] = mod - h[i];
}
b[0] = 1;
for (int i = 0; i <= n; i++) for (int j = i + 1; j >= 0; j--)
a[j] = ((j ? a[j-1] : 0) + 1ll * (mod - i) * a[j] + 1ll * h[i] * b[j]) % mod,
b[j] = ((j ? b[j-1] : 0) + 1ll * (mod - i) * b[j]) % mod;
for (int i = 0; i <= n; i++) ans = (ans + 1ll * a[i] * fac[i] % mod * ksm(i, x)) % mod;
cout << ans << "\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5596kb
input:
1 2 3 1
output:
110
result:
ok 1 number(s): "110"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
4 5 7 12
output:
881078346
result:
ok 1 number(s): "881078346"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 1 7 8
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
13 26 88 45
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 377ms
memory: 8624kb
input:
100 300 400 1515897
output:
279831696
result:
ok 1 number(s): "279831696"
Test #6:
score: 0
Accepted
time: 311ms
memory: 7996kb
input:
120 310 298 1155114
output:
903227392
result:
ok 1 number(s): "903227392"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
1 1 2 1
output:
18
result:
ok 1 number(s): "18"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5760kb
input:
5 5 10 1919810
output:
696652039
result:
ok 1 number(s): "696652039"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 315ms
memory: 7696kb
input:
1 1 798 15154848
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 320ms
memory: 7588kb
input:
1 399 400 1616897
output:
987648925
result:
ok 1 number(s): "987648925"
Test #12:
score: 0
Accepted
time: 321ms
memory: 7804kb
input:
400 398 2 45458123
output:
830387421
result:
ok 1 number(s): "830387421"
Test #13:
score: 0
Accepted
time: 6ms
memory: 6076kb
input:
89 75 18 66278
output:
940243796
result:
ok 1 number(s): "940243796"
Test #14:
score: 0
Accepted
time: 871ms
memory: 8164kb
input:
333 333 334 1
output:
60970749
result:
ok 1 number(s): "60970749"
Test #15:
score: 0
Accepted
time: 868ms
memory: 8956kb
input:
334 333 333 1000000000
output:
159064905
result:
ok 1 number(s): "159064905"
Test #16:
score: 0
Accepted
time: 623ms
memory: 8384kb
input:
1 499 500 1515987
output:
880517266
result:
ok 1 number(s): "880517266"
Test #17:
score: 0
Accepted
time: 620ms
memory: 8356kb
input:
500 498 2 1514789
output:
93909141
result:
ok 1 number(s): "93909141"
Test #18:
score: 0
Accepted
time: 772ms
memory: 8960kb
input:
250 250 500 19198877
output:
172243832
result:
ok 1 number(s): "172243832"
Test #19:
score: 0
Accepted
time: 968ms
memory: 8924kb
input:
300 300 400 75787941
output:
778545661
result:
ok 1 number(s): "778545661"
Test #20:
score: 0
Accepted
time: 0ms
memory: 5720kb
input:
7 16 11 1568
output:
725510153
result:
ok 1 number(s): "725510153"
Extra Test:
score: 0
Extra Test Passed