結果

問題 No.829 成長関数インフレ中
ユーザー PachicobuePachicobue
提出日時 2018-12-06 17:52:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,326 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 76,616 KB
実行使用メモリ 15,888 KB
最終ジャッジ日時 2023-10-13 17:24:10
合計ジャッジ時間 8,425 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
15,888 KB
testcase_01 AC 5 ms
11,584 KB
testcase_02 AC 5 ms
11,528 KB
testcase_03 AC 4 ms
11,708 KB
testcase_04 AC 4 ms
11,568 KB
testcase_05 AC 5 ms
11,560 KB
testcase_06 AC 5 ms
11,776 KB
testcase_07 AC 5 ms
11,580 KB
testcase_08 AC 5 ms
11,556 KB
testcase_09 AC 5 ms
11,648 KB
testcase_10 AC 5 ms
11,784 KB
testcase_11 AC 5 ms
11,572 KB
testcase_12 AC 476 ms
11,564 KB
testcase_13 AC 38 ms
11,536 KB
testcase_14 AC 328 ms
11,716 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];

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++;
    }
    for (int i = 0; i <= N; i++) { std::cerr << dp[i] << " "; }
    std::cerr << std::endl;
    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