QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797762#8942. Sugar Sweet 3hhoppitreeAC ✓894ms10292kbC++203.0kb2024-12-03 17:41:372024-12-03 17:41:37

Judging History

你现在查看的是最新测评结果

  • [2024-12-03 17:41:37]
  • 评测
  • 测评结果:AC
  • 用时:894ms
  • 内存:10292kb
  • [2024-12-03 17:41:37]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1005, P = 1e9 + 7;

int ksm(int x, int y = P - 2) {
    int res = 1;
    while (y) {
        if (y & 1) res = 1ll * res * x % P;
        x = 1ll * x * x % P;
        y >>= 1;
    }
    return res;
}

int fac[N], iFac[N], f[N][N], tf[N][N], g[N];

int C(int x, int y) {
    return 1ll * fac[x] * iFac[y] % P * iFac[x - y] % P;
}

int Catalan(int x) {
    return 1ll * C(x + x, x) * ksm(x + 1) % P;
}

typedef vector<int> poly;

poly operator + (poly x, poly y) {
    if (x.size() < y.size()) swap(x, y);
    poly res = x;
    for (int i = 0; i < (int)y.size(); ++i) {
        res[i] = (res[i] + y[i]) % P;
    }
    return res;
}

poly operator * (poly x, poly y) {
    poly res(x.size() + y.size() - 1);
    for (int i = 0; i < (int)x.size(); ++i) {
        for (int j = 0; j < (int)y.size(); ++j) {
            res[i + j] = (res[i + j] + 1ll * x[i] * y[j]) % P;
        }
    }
    return res;
}

signed main() {
    int x, y, z, v; scanf("%d%d%d%d", &x, &y, &z, &v);
    int n = x + y + z, m = n / 2, L = max({x, y, z});
    if ((n & 1) || L > m) return 0 & puts("0");
    for (int i = fac[0] = iFac[0] = 1; i <= n; ++i) {
        fac[i] = 1ll * fac[i - 1] * i % P;
        iFac[i] = ksm(fac[i]);
    }
    f[0][0] = 1;
    for (int i = 1; i <= L; ++i) {
        f[i][1] = Catalan(i - 1);
        for (int j = 2; j <= i; ++j) {
            for (int k = 1; k <= i; ++k) {
                f[i][j] = (f[i][j] + 1ll * f[i - k][j - 1] * f[k][1]) % P;
            }
        }
    }
    for (int i = 0; i <= L; ++i) {
        for (int j = 0; j <= m; ++j) {
            for (int k = 0, now = 1; k <= i; ++k) {
                tf[i][j] = (tf[i][j] + 1ll * f[i][k] * now % P * iFac[k]) % P;
                now = 1ll * now * j % P;
            }
        }
    }
    for (int a = 0; a <= x; ++a) {
        for (int b = 0; b <= y; ++b) {
            int c = m - a - b;
            if (c > z || c < 0) continue;
            int coef = 0;
            for (int cab = 0; cab <= x - a && cab <= b; ++cab) {
                int cac = x - a - cab, ccb = b - cab, cca = z - c - ccb, cba = a - cca, cbc = c - cac;
                if (cab >= 0 && cac >= 0 && ccb >= 0 && cca >= 0 && cba >= 0 && cbc >= 0) {
                    coef = (coef + 1ll * C(cba + cca, cba) * C(cab + ccb, cab) % P * C(cac + cbc, cac)) % P;
                }
            }
            for (int i = 0; i <= m; ++i) {
                g[i] = (g[i] + 1ll * tf[a][i] * tf[b][i] % P * tf[c][i] % P * coef) % P;
            }
        }
    }
    poly sum;
    for (int i = 0; i <= m; ++i) {
        poly res = {g[i]};
        for (int j = 0; j <= m; ++j) {
            if (i != j) res = res * (poly){(int)(-1ll * j * ksm(i - j) % P), ksm(i - j)};
        }
        sum = sum + res;
    }
    int res = 0;
    for (int i = 1; i <= m; ++i) res = (res + 1ll * fac[i] * sum[i] % P * ksm(i, v)) % P;
    printf("%d\n", (res % P + P) % P);
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6180kb

input:

1 2 3 1

output:

110

result:

ok 1 number(s): "110"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5904kb

input:

4 5 7 12

output:

881078346

result:

ok 1 number(s): "881078346"

Test #3:

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

input:

1 1 7 8

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

13 26 88 45

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 454ms
memory: 7592kb

input:

100 300 400 1515897

output:

279831696

result:

ok 1 number(s): "279831696"

Test #6:

score: 0
Accepted
time: 303ms
memory: 7996kb

input:

120 310 298 1155114

output:

903227392

result:

ok 1 number(s): "903227392"

Test #7:

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

input:

1 1 2 1

output:

18

result:

ok 1 number(s): "18"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5872kb

input:

5 5 10 1919810

output:

696652039

result:

ok 1 number(s): "696652039"

Test #9:

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

input:

1 1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

1 1 798 15154848

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 411ms
memory: 9608kb

input:

1 399 400 1616897

output:

987648925

result:

ok 1 number(s): "987648925"

Test #12:

score: 0
Accepted
time: 412ms
memory: 9604kb

input:

400 398 2 45458123

output:

830387421

result:

ok 1 number(s): "830387421"

Test #13:

score: 0
Accepted
time: 8ms
memory: 6228kb

input:

89 75 18 66278

output:

940243796

result:

ok 1 number(s): "940243796"

Test #14:

score: 0
Accepted
time: 693ms
memory: 7564kb

input:

333 333 334 1

output:

60970749

result:

ok 1 number(s): "60970749"

Test #15:

score: 0
Accepted
time: 688ms
memory: 7304kb

input:

334 333 333 1000000000

output:

159064905

result:

ok 1 number(s): "159064905"

Test #16:

score: 0
Accepted
time: 780ms
memory: 10016kb

input:

1 499 500 1515987

output:

880517266

result:

ok 1 number(s): "880517266"

Test #17:

score: 0
Accepted
time: 777ms
memory: 10292kb

input:

500 498 2 1514789

output:

93909141

result:

ok 1 number(s): "93909141"

Test #18:

score: 0
Accepted
time: 894ms
memory: 10000kb

input:

250 250 500 19198877

output:

172243832

result:

ok 1 number(s): "172243832"

Test #19:

score: 0
Accepted
time: 786ms
memory: 9672kb

input:

300 300 400 75787941

output:

778545661

result:

ok 1 number(s): "778545661"

Test #20:

score: 0
Accepted
time: 1ms
memory: 6244kb

input:

7 16 11 1568

output:

725510153

result:

ok 1 number(s): "725510153"

Extra Test:

score: 0
Extra Test Passed