QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#449378#8526. Polygon IIucup-team3734RE 1ms3636kbC++233.7kb2024-06-21 05:44:062024-06-21 05:44:06

Judging History

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

  • [2024-06-21 05:44:06]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3636kb
  • [2024-06-21 05:44:06]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long u64;
typedef double lf;

const int mod = 1'000'000'000 + 7;

template<typename T>
T add(T x) {
    return x;
}
template<typename T, typename... Ts>
T add(T x, Ts... y) {
    T res = x + add(y...);
    if (res >= mod)
        res -= mod;
    return res;
}
template<typename T, typename... Ts>
T sub(T x, Ts... y) {
    return add(x, mod - add(y...));
}
template<typename T, typename... Ts>
void udd(T &x, Ts... y) {
    x = add(x, y...);
}
template<typename T>
T mul(T x) {
    return x;
}
template<typename T, typename... Ts>
T mul(T x, Ts... y) {
    return (x * 1ll * mul(y...)) % mod;
}
template<typename T, typename... Ts>
void uul(T &x, Ts... y) {
    x = mul(x, y...);
}

int bin(int a, i64 deg) {
    int r = 1;
    while (deg) {
        if (deg & 1)
            uul(r, a);
        deg >>= 1;
        uul(a, a);
    }
    return r;
}
int inv(int x) {
    assert(x);
    return bin(x, mod - 2);
}

const int maxb = 55;

void solve() {
    int n;
    cin >> n;
    vector<int> cnt(maxb + 1);
    vector<int> cnt_bit(maxb + 1);
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
        maxv = max(maxv, x);
        for (int j = 0; j < x; ++j) {
            cnt_bit[j]++;
        }
    }

    int half = inv(2);
    
    vector<int> pows(maxb * n + 1);
    pows[0] = 1;
    for (int i = 1; i <= maxb * n; ++i) {
        pows[i] = mul(pows[i - 1], half);
    }
    
    vector< vector<int> > choose(maxb + 1, vector<int>(maxb + 1));
    choose[0][0] = 1;
    for (int i = 1; i <= maxb; ++i) {
        choose[i][0] = 1;
        for (int j = 1; j <= i; ++j) {
            choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
        }
    }
    vector<int> cdf(n + 1);
    int inv_fact = 1;
    for (int i = 0; i < n; ++i) {
        uul(inv_fact, inv(i + 1));
    }
    for (int i = 0; i <= n; ++i) {
        int sgn = 1;
        for (int k = 0; k <= i; ++k) {
            udd(cdf[i], mul(sgn, choose[n][k], bin(sub(i, k), n)));
            sgn = sub(0, sgn);
        }
        uul(cdf[i], inv_fact);
    }

    vector< vector<int> > dp(maxv + 1, vector<int>(2 * n + 1));
    for (int i = 0; i < n; ++i) {
        dp[0][i] = sub(cdf[i + 1], cdf[i]);
    }
    for (int i = 1; i <= maxv; ++i) {
        for (int j = 0; j <= 2 * n; ++j) {
            int &res = dp[i][j];
            for (int k = 0; k <= cnt_bit[i - 1]; ++k) {
                int v = 0;
                if (0 <= 2 * j - k && 2 * j - k <= 2 * n) {
                    udd(v, dp[i - 1][2 * j - k]);
                }
                if (0 <= 2 * j - k + 1 && 2 * j - k + 1 <= 2 * n) {
                    udd(v, dp[i - 1][2 * j - k + 1]);
                }
                uul(v, choose[cnt_bit[i - 1]][k], pows[cnt_bit[i - 1]]);
                udd(res, v);
            }
        }
    }
    vector<int> prob_ge(maxv + 1);
    for (int i = 0; i <= maxv; ++i) {
        int high = 0;
        for (int j = i; j <= maxv; ++j) {
            high += cnt_bit[j];
        }
        prob_ge[i] = sub(1, pows[high]);
        int v = 0;
        for (int j = 1; j <= 2 * n; ++j) {
            udd(v, dp[i][j]);
        }
        udd(prob_ge[i], mul(v, pows[high]));
    }
    int ans = 0;
    for (int i = 0; i <= maxv; ++i) {
        udd(ans, mul(cnt[i], sub(1, prob_ge[i])));
    }
    cout << sub(1, ans) << '\n';
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0 2 0

output:

166666668

result:

ok 1 number(s): "166666668"

Test #2:

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

input:

3
0 0 0

output:

500000004

result:

ok 1 number(s): "500000004"

Test #3:

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

input:

3
5 6 7

output:

208333335

result:

ok 1 number(s): "208333335"

Test #4:

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

input:

3
0 25 50

output:

889268532

result:

ok 1 number(s): "889268532"

Test #5:

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

input:

10
39 11 25 1 12 44 10 46 27 15

output:

913863330

result:

ok 1 number(s): "913863330"

Test #6:

score: -100
Runtime Error

input:

57
43 22 3 16 7 5 24 32 25 16 41 28 24 30 28 10 32 48 41 43 34 37 48 34 3 9 21 41 49 25 2 0 36 45 34 33 45 9 42 29 43 9 38 34 44 33 44 6 46 39 22 36 40 37 19 34 3

output:


result: