結果

問題 No.829 成長関数インフレ中
ユーザー PachicobuePachicobue
提出日時 2018-12-06 17:21:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,580 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 76,084 KB
実行使用メモリ 18,724 KB
最終ジャッジ日時 2023-10-13 17:23:16
合計ジャッジ時間 6,789 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
18,724 KB
testcase_01 AC 4 ms
11,572 KB
testcase_02 AC 4 ms
11,560 KB
testcase_03 AC 4 ms
11,608 KB
testcase_04 AC 4 ms
11,564 KB
testcase_05 AC 4 ms
11,552 KB
testcase_06 AC 4 ms
11,828 KB
testcase_07 AC 4 ms
11,848 KB
testcase_08 AC 3 ms
11,572 KB
testcase_09 AC 4 ms
11,592 KB
testcase_10 AC 4 ms
11,624 KB
testcase_11 AC 3 ms
11,584 KB
testcase_12 AC 25 ms
11,564 KB
testcase_13 AC 6 ms
11,560 KB
testcase_14 AC 18 ms
11,564 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr int MAX = 200000;
ll dp[MAX];
int R[MAX];
ll fact[2 * MAX + 1];
ll inv[2 * MAX + 1];
template <typename T>
constexpr std::pair<T, T> extgcd(const T a, const T b)
{
    if (b == 0) { return std::pair<T, T>{1, 0}; }
    const auto p = extgcd(b, a % b);
    return {p.second, p.first - p.second * (a / b)};
}
template <typename T>
constexpr T inverse(const T a, const T mod = MOD) { return (mod + extgcd(a, mod).first % mod) % mod; }

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N;
    ll P;
    std::cin >> N >> P;
    std::fill(fact, fact + 2 * MAX + 1, 1), std::fill(inv, inv + 2 * MAX + 1, 1);
    for (ll i = 2; i <= 2 * N; i++) { fact[i] = (fact[i - 1] * i) % MOD, inv[i] = ((MOD - MOD / i) * inv[MOD % i]) % MOD; }
    for (int i = 1; i <= 2 * N; i++) { (inv[i] *= inv[i - 1]) %= MOD; }
    for (int i = 0, a; i < N; i++) { std::cin >> a, R[a]++; }
    dp[0] = 1;
    for (int i = N - 1, k = 0, max = 0; i >= 0; k += R[i], i--) {
        const int r = R[i];
        if (r == 0) { continue; }
        const ll alpha = (r * fact[r + k - 1] % MOD) * inv[k] % MOD;
        const ll beta = (k * fact[r + k - 1] % MOD) * inv[k] % MOD;
        for (int j = max; j >= 0; j--) { (dp[j + 1] += alpha * dp[j] % MOD) %= MOD, (dp[j] *= beta) %= MOD; }
        max++;
    }
    ll ans = 0;
    for (ll i = 0, p = 1; i <= N; i++, (p *= P) %= MOD) { (ans += (i * p % MOD) * dp[i] % MOD) %= MOD; }
    std::cout << ans << std::endl;
}
0