結果

問題 No.995 タピオカオイシクナーレ
ユーザー tomatoma
提出日時 2020-02-21 22:07:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 2,885 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 172,684 KB
実行使用メモリ 7,136 KB
最終ジャッジ日時 2023-07-30 06:25:08
合計ジャッジ時間 3,364 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,168 KB
testcase_01 AC 7 ms
6,172 KB
testcase_02 AC 7 ms
6,304 KB
testcase_03 AC 7 ms
6,456 KB
testcase_04 AC 7 ms
6,372 KB
testcase_05 AC 7 ms
6,304 KB
testcase_06 AC 7 ms
6,304 KB
testcase_07 AC 7 ms
6,232 KB
testcase_08 AC 7 ms
6,304 KB
testcase_09 AC 7 ms
6,308 KB
testcase_10 AC 7 ms
6,292 KB
testcase_11 AC 7 ms
6,180 KB
testcase_12 AC 7 ms
6,372 KB
testcase_13 AC 7 ms
6,236 KB
testcase_14 AC 7 ms
6,148 KB
testcase_15 AC 7 ms
6,176 KB
testcase_16 AC 45 ms
6,920 KB
testcase_17 AC 45 ms
6,932 KB
testcase_18 AC 44 ms
6,964 KB
testcase_19 AC 45 ms
6,964 KB
testcase_20 AC 45 ms
7,096 KB
testcase_21 AC 45 ms
7,096 KB
testcase_22 AC 44 ms
7,136 KB
testcase_23 AC 44 ms
7,020 KB
testcase_24 AC 44 ms
6,960 KB
testcase_25 AC 45 ms
6,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;

struct ModInt {
    static const ll MOD = 1000000007;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(num_%MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }

struct Comb {
    static constexpr ll LIM = 200000;
    static vector<ModInt> fact, inv;

    static void init() {
        fact.resize(LIM, 1);
        inv.resize(LIM, 1);

        REP(i, 1, LIM)fact[i] = fact[i - 1] * i;
        inv[LIM - 1] = fact[LIM - 1].inv();
        for (ll i = LIM - 2; i > 0; i--)inv[i] = inv[i + 1] * (i + 1);
    }

    static ll comb(ll n, ll k) {
        if (n < k)return 0ll;
        return (fact[n] * inv[k] * inv[n - k]).get();
    }
};
vector<ModInt> Comb::fact;
vector<ModInt> Comb::inv;

int main()
{
    // input
    ll N, M, K, p, q;
    cin >> N >> M >> K >> p >> q;
    vector<ll> b(N);
    rep(i, N)cin >> b[i];

    // preprocess
    Comb::init();
    ModInt alpha(p);
    alpha /= q;
    ModInt z(1);
    z -= alpha * 2;
    K %= ModInt::MOD - 1;
    z = z.pow(K);

    ModInt milk2milk = (ModInt(1) + z) / 2;
    ModInt kitchin2milk = (ModInt(1) - z) / 2;

    // calc
    ModInt res(0);
    rep(i, N) {
        res += ModInt(b[i])* (i < M ? milk2milk : kitchin2milk);
    }
    cout << res << endl;
    return 0;
}
0