結果

問題 No.766 金魚すくい
ユーザー Manuel1024Manuel1024
提出日時 2023-08-17 10:11:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,816 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 80,100 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2023-08-17 10:11:40
合計ジャッジ時間 6,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
18,648 KB
testcase_01 AC 18 ms
18,620 KB
testcase_02 AC 19 ms
18,568 KB
testcase_03 AC 19 ms
18,548 KB
testcase_04 AC 18 ms
18,868 KB
testcase_05 AC 18 ms
18,584 KB
testcase_06 AC 18 ms
18,588 KB
testcase_07 AC 18 ms
18,564 KB
testcase_08 AC 18 ms
18,584 KB
testcase_09 AC 19 ms
18,888 KB
testcase_10 AC 18 ms
18,696 KB
testcase_11 AC 18 ms
18,732 KB
testcase_12 AC 18 ms
18,620 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 20 ms
18,632 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 97 ms
19,644 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 29 ms
18,792 KB
testcase_36 AC 30 ms
18,496 KB
testcase_37 AC 97 ms
19,636 KB
testcase_38 AC 96 ms
19,692 KB
testcase_39 AC 97 ms
19,908 KB
testcase_40 AC 95 ms
19,688 KB
testcase_41 AC 74 ms
19,916 KB
testcase_42 AC 72 ms
19,620 KB
testcase_43 AC 18 ms
18,860 KB
testcase_44 AC 18 ms
18,836 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];

    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