結果

問題 No.766 金魚すくい
ユーザー pekempeypekempey
提出日時 2018-12-14 01:29:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 1,500 ms
コード長 1,359 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 50,300 KB
実行使用メモリ 8,720 KB
最終ジャッジ日時 2023-10-25 09:47:36
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,016 KB
testcase_01 AC 6 ms
8,016 KB
testcase_02 AC 5 ms
8,016 KB
testcase_03 AC 6 ms
8,016 KB
testcase_04 AC 6 ms
8,016 KB
testcase_05 AC 6 ms
8,016 KB
testcase_06 AC 6 ms
8,016 KB
testcase_07 AC 5 ms
8,016 KB
testcase_08 AC 6 ms
8,016 KB
testcase_09 AC 6 ms
8,016 KB
testcase_10 AC 6 ms
8,016 KB
testcase_11 AC 6 ms
8,016 KB
testcase_12 AC 6 ms
8,016 KB
testcase_13 AC 6 ms
8,016 KB
testcase_14 AC 7 ms
8,016 KB
testcase_15 AC 7 ms
8,016 KB
testcase_16 AC 7 ms
8,016 KB
testcase_17 AC 7 ms
8,016 KB
testcase_18 AC 6 ms
8,016 KB
testcase_19 AC 7 ms
8,016 KB
testcase_20 AC 7 ms
8,016 KB
testcase_21 AC 7 ms
8,016 KB
testcase_22 AC 7 ms
8,016 KB
testcase_23 AC 80 ms
8,680 KB
testcase_24 AC 78 ms
8,676 KB
testcase_25 AC 85 ms
8,716 KB
testcase_26 AC 81 ms
8,648 KB
testcase_27 AC 85 ms
8,712 KB
testcase_28 AC 81 ms
8,656 KB
testcase_29 AC 81 ms
8,660 KB
testcase_30 AC 80 ms
8,656 KB
testcase_31 AC 84 ms
8,720 KB
testcase_32 AC 82 ms
8,664 KB
testcase_33 AC 40 ms
8,680 KB
testcase_34 AC 40 ms
8,684 KB
testcase_35 AC 21 ms
8,016 KB
testcase_36 AC 20 ms
8,016 KB
testcase_37 AC 83 ms
8,684 KB
testcase_38 AC 84 ms
8,676 KB
testcase_39 AC 81 ms
8,712 KB
testcase_40 AC 81 ms
8,660 KB
testcase_41 AC 78 ms
8,708 KB
testcase_42 AC 74 ms
8,672 KB
testcase_43 AC 6 ms
8,016 KB
testcase_44 AC 6 ms
8,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>

#define M 1000000007

int n, m;
long long p;
long long V[100000];

long long inv[200001];
long long F[200001];
long long IF[200001];

long long C(int n, int r) {
    return F[n] * IF[n - r] % M * IF[r] % M;
}

long long mpow(long long a, long long b) {
    if (b == 0) return 1;
    if (b % 2 == 1) return a * mpow(a, b - 1) % M;
    return mpow(a * a % M, b / 2);
}

int main(void) {
    inv[1] = 1;
    for (int i = 2; i <= 200000; i++) {
        inv[i] = inv[M % i] * (M - M / i) % M;
    }
    F[0] = 1;
    IF[0] = 1;
    for (int i = 1; i <= 200000; i++) {
        F[i] = i * F[i - 1] % M;
        IF[i] = inv[i] * IF[i - 1] % M;
    }
    scanf("%d %d %lld", &n, &m, &p);
    long long q = (100 - p) * inv[100] % M;
    p = p * inv[100] % M;
    for (int i = 0; i < n; i++) {
        scanf("%lld", V + i);
    }
    std::sort(V, V + n);
    std::reverse(V, V + n);
    long long ans = 0;
    long long s = 0;
    for (int i = 1; i <= n - 1; i++) {
        s = (s + V[i - 1]) % M;
        ans += s * C(m - 1 + i, i) % M * mpow(p, m - 1) % M * mpow(q, i) % M * p % M;
        ans %= M;
    }
    s = (s + V[n - 1]) % M;
    for (int i = 0; i <= m - 1; i++) {
        ans += s * C(n - 1 + i, i) % M * mpow(p, i) % M * mpow(q, n - 1) % M * q % M;
        ans %= M;
    }
    printf("%lld\n", ans);
    return 0;
}

0