結果

問題 No.766 金魚すくい
ユーザー treeonetreeone
提出日時 2018-11-25 00:29:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 1,500 ms
コード長 1,286 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 206,268 KB
実行使用メモリ 6,652 KB
最終ジャッジ日時 2023-08-26 05:03:26
合計ジャッジ時間 7,061 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
6,652 KB
testcase_01 AC 40 ms
6,512 KB
testcase_02 AC 41 ms
6,428 KB
testcase_03 AC 41 ms
6,504 KB
testcase_04 AC 39 ms
6,432 KB
testcase_05 AC 41 ms
6,508 KB
testcase_06 AC 40 ms
6,452 KB
testcase_07 AC 41 ms
6,508 KB
testcase_08 AC 41 ms
6,432 KB
testcase_09 AC 40 ms
6,424 KB
testcase_10 AC 41 ms
6,576 KB
testcase_11 AC 40 ms
6,576 KB
testcase_12 AC 41 ms
6,428 KB
testcase_13 AC 41 ms
6,440 KB
testcase_14 AC 41 ms
6,516 KB
testcase_15 AC 40 ms
6,536 KB
testcase_16 AC 39 ms
6,520 KB
testcase_17 AC 41 ms
6,644 KB
testcase_18 AC 42 ms
6,460 KB
testcase_19 AC 41 ms
6,596 KB
testcase_20 AC 39 ms
6,448 KB
testcase_21 AC 40 ms
6,452 KB
testcase_22 AC 41 ms
6,512 KB
testcase_23 AC 103 ms
6,452 KB
testcase_24 AC 99 ms
6,584 KB
testcase_25 AC 107 ms
6,456 KB
testcase_26 AC 101 ms
6,588 KB
testcase_27 AC 104 ms
6,572 KB
testcase_28 AC 95 ms
6,472 KB
testcase_29 AC 100 ms
6,452 KB
testcase_30 AC 96 ms
6,436 KB
testcase_31 AC 101 ms
6,476 KB
testcase_32 AC 102 ms
6,580 KB
testcase_33 AC 90 ms
6,588 KB
testcase_34 AC 91 ms
6,468 KB
testcase_35 AC 41 ms
6,520 KB
testcase_36 AC 40 ms
6,448 KB
testcase_37 AC 104 ms
6,540 KB
testcase_38 AC 102 ms
6,468 KB
testcase_39 AC 103 ms
6,572 KB
testcase_40 AC 101 ms
6,436 KB
testcase_41 AC 81 ms
6,444 KB
testcase_42 AC 81 ms
6,440 KB
testcase_43 AC 42 ms
6,512 KB
testcase_44 AC 43 ms
6,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

long long mod_pow(long long x, long long n){
    if(n == 0) return 1;
    long long res = mod_pow(x*x % mod, n / 2);
    if(n & 1) res = res*x % mod;
    return res;
}

const int MAX_NUM = 200010;
long long fact[MAX_NUM], inv[MAX_NUM];

long long comb(long long n, long long k){
    if(n < k || n < 0 || k < 0) return 0;
    if(fact[0] == 0){
        fact[0] = 1; inv[0] = 1;
        for(int i = 1; i < MAX_NUM; i++){
            fact[i] = fact[i - 1] * i % mod;
            inv[i] = mod_pow(fact[i], mod - 2);
        }
    }
    return fact[n] * inv[k] % mod * inv[n - k] % mod; 
}

int main(){
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v.rbegin(), v.rend());
    for(int i = 1; i < n; i++) (v[i] += v[i - 1]) %= mod;
    long long p1 = p * mod_pow(100, mod - 2) % mod;
    long long p2 = (1 - p1 + mod) % mod;
    long long sum = 0, ans = 0;
    for(int i = 0; i < n; i++){
        long long tmp = comb(m + i - 1, i) * mod_pow(p1, m) % mod * mod_pow(p2, i) % mod;
        (sum += tmp) %= mod;
        if(i) (ans += tmp * v[i - 1] % mod) %= mod;
    }
    (ans += (1 - sum + mod) % mod * v[n - 1] % mod) %= mod;
    cout << ans << endl;
}
0