結果

問題 No.766 金魚すくい
ユーザー Manuel1024Manuel1024
提出日時 2023-08-17 10:15:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 1,500 ms
コード長 1,822 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 79,364 KB
実行使用メモリ 19,956 KB
最終ジャッジ日時 2023-08-17 10:15:14
合計ジャッジ時間 4,912 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
18,460 KB
testcase_01 AC 16 ms
18,644 KB
testcase_02 AC 17 ms
18,768 KB
testcase_03 AC 16 ms
18,548 KB
testcase_04 AC 17 ms
18,728 KB
testcase_05 AC 16 ms
18,664 KB
testcase_06 AC 16 ms
18,824 KB
testcase_07 AC 17 ms
19,024 KB
testcase_08 AC 18 ms
18,600 KB
testcase_09 AC 17 ms
18,608 KB
testcase_10 AC 16 ms
18,868 KB
testcase_11 AC 16 ms
18,744 KB
testcase_12 AC 15 ms
18,664 KB
testcase_13 AC 16 ms
18,740 KB
testcase_14 AC 17 ms
19,012 KB
testcase_15 AC 18 ms
18,832 KB
testcase_16 AC 18 ms
18,828 KB
testcase_17 AC 18 ms
18,744 KB
testcase_18 AC 16 ms
18,756 KB
testcase_19 AC 18 ms
18,796 KB
testcase_20 AC 19 ms
18,464 KB
testcase_21 AC 17 ms
18,708 KB
testcase_22 AC 17 ms
18,772 KB
testcase_23 AC 93 ms
19,956 KB
testcase_24 AC 95 ms
19,784 KB
testcase_25 AC 97 ms
19,884 KB
testcase_26 AC 93 ms
19,736 KB
testcase_27 AC 96 ms
19,788 KB
testcase_28 AC 92 ms
19,796 KB
testcase_29 AC 91 ms
19,760 KB
testcase_30 AC 91 ms
19,852 KB
testcase_31 AC 96 ms
19,832 KB
testcase_32 AC 92 ms
19,824 KB
testcase_33 AC 68 ms
19,880 KB
testcase_34 AC 68 ms
19,820 KB
testcase_35 AC 28 ms
18,668 KB
testcase_36 AC 28 ms
18,740 KB
testcase_37 AC 94 ms
19,764 KB
testcase_38 AC 95 ms
19,860 KB
testcase_39 AC 96 ms
19,796 KB
testcase_40 AC 92 ms
19,752 KB
testcase_41 AC 71 ms
19,764 KB
testcase_42 AC 71 ms
19,808 KB
testcase_43 AC 15 ms
18,756 KB
testcase_44 AC 15 ms
18,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr ll MOD = 1'000'000'007;

struct Combination{
    using ll = long long;
    const int n;
    // const int MOD = 998244353;
    vector<ll> fac, ifac;
    ll mp(ll a, ll x) const {
        ll res = 1;
        for(; x > 0; x >>= 1){
            if(x&1){
                res *= a; res %= MOD;
            }
            a *= a; a %= MOD;
        }
        return res;
    }
    Combination(int _n = 1000000): n(_n), fac(vector<ll>(_n+1)), ifac(vector<ll>(_n+1)){
        fac[0] = 1;
        for(int i = 1; i <= n; i++) fac[i] = (fac[i-1]*i)%MOD;
        ifac[n] = mp(fac[n], MOD-2);
        for(int i = n; i > 0; i--) ifac[i-1] = (ifac[i]*i)%MOD;
    }

    ll operator()(int n, int k) const {
        if (k < 0 || k > n) return 0;
        return fac[n]*ifac[k]%MOD*ifac[n-k]%MOD;
    }
};

ll modpow(ll a, ll x){
    ll res = 1;
    a %= MOD;
    for(; x > 0; x >>= 1){
        if(x & 1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
    }
    return res;
}

ll inv(ll a){
    return modpow(a, MOD-2);
}

int main(){
    int n, m, p; cin >> n >> m >> p;
    vector<int> v(n);
    for(auto &it: v) cin >> it;

    sort(v.begin(), v.end(), greater<int>());
    vector<ll> vtot(n+1, 0);
    for(int i = 0; i < n; i++) vtot[i+1] = (vtot[i]+v[i])%MOD;

    Combination comb{};
    ll ans = 0;
    const ll q = inv(100)*p%MOD;
    const ll r = inv(100)*(100-p)%MOD;
    for(int i = 0; i < n; i++){
        ans += modpow(q, m)*modpow(r, i)%MOD*comb(m+i-1, i)%MOD*vtot[i]%MOD;
        ans %= MOD;
    }
    for(int i = 0; i < m; i++){
        ans += modpow(r, n)*modpow(q, i)%MOD*comb(n+i-1, i)%MOD*vtot[n]%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0