QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446766#8526. Polygon IIucup-team3678RE 1ms3896kbC++141.9kb2024-06-17 15:59:382024-06-17 15:59:39

Judging History

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

  • [2024-06-17 15:59:39]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3896kb
  • [2024-06-17 15:59:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

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

int jc[N], inv[N], pw[N], pw2[N];

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

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 a[N], b[N], f[M][N];

signed main() {
    int n, mx = 0; scanf("%d", &n);
    for (int i = jc[0] = inv[0] = 1; i <= n; ++i) {
        jc[i] = 1ll * jc[i - 1] * i % P;
        inv[i] = (i == 1 ? 1 : 1ll * (P - P / i) * inv[P % i] % P);
    }
    pw2[0] = 1;
    for (int i = 1; i <= n; ++i) {
        inv[i] = 1ll * inv[i - 1] * inv[i] % P;
        pw[i] = ksm(i, n);
        pw2[i] = ksm((P + 1) >> 1, i);
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        mx = max(mx, a[i]);
        for (int j = 0; j < a[i]; ++j) ++b[j];
    }
    for (int i = 1; i <= n; ++i) {
        int s = 0;
        for (int j = 0; j < i; ++j) {
            s = (s + ((j & 1) ? P - 1ll : 1ll) * C(n, j) % P * pw[i - j] % P * inv[n]) % P;
        }
        f[0][i - 1] = s;
    }
    for (int i = n - 1; i; --i) {
        f[0][i] = (f[0][i] - f[0][i - 1] + P) % P;
    }
    for (int i = 1; i <= mx; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= b[i - 1] && k <= j * 2 + 1; ++k) {
                f[i][j] = (f[i][j] + 1ll * C(b[i - 1], k) * pw2[b[i - 1]] % P * ((j * 2 - k >= 0 ? f[i - 1][j * 2 - k] : 0) + f[i - 1][j * 2 - k + 1])) % P;
            }
        }
    }
    int res = 1;
    for (int i = 0; i <= mx; ++i) {
        int t = (!i ? n : b[i - 1]) - b[i], S = 0;
        for (int j = i; j < mx; ++j) S += b[j];
        res = (res - 1ll * f[i][0] * pw2[S] % P * t % P + P) % P;
    }
    printf("%d\n", res);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3896kb

input:

3
0 2 0

output:

166666668

result:

ok 1 number(s): "166666668"

Test #2:

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

input:

3
0 0 0

output:

500000004

result:

ok 1 number(s): "500000004"

Test #3:

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

input:

3
5 6 7

output:

208333335

result:

ok 1 number(s): "208333335"

Test #4:

score: -100
Runtime Error

input:

3
0 25 50

output:


result: