結果

問題 No.995 タピオカオイシクナーレ
ユーザー ganmodokixganmodokix
提出日時 2020-02-08 13:43:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 4,697 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 169,428 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:02:58
合計ジャッジ時間 3,387 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 41 ms
5,376 KB
testcase_17 AC 40 ms
5,376 KB
testcase_18 AC 42 ms
5,376 KB
testcase_19 AC 39 ms
5,376 KB
testcase_20 AC 39 ms
5,376 KB
testcase_21 AC 40 ms
5,376 KB
testcase_22 AC 40 ms
5,376 KB
testcase_23 AC 41 ms
5,376 KB
testcase_24 AC 41 ms
5,376 KB
testcase_25 AC 40 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール
// 剰余演算
constexpr ll p = 1000000007LL; // 10^9+7
ll powll(ll a, ll n) {
    if (n == 0) {
        return 1LL;
    } else if (n == 1) {
        return a % p;
    } else {
        ll temp = powll(a, n/2);
        temp = temp * temp % p;
        return n % 2 ? temp * a % p : temp;
    }
}

inline ll invll(ll a) { return powll(a, p-2); }

vector<ll> fac_cache = {1}, invfac_cache = {1};
void make_fac_cache(ll a) {
    ll old_max = fac_cache.size() - 1;
    if (a > old_max) {
        fac_cache   .resize(a+1);
        invfac_cache.resize(a+1);
        for (ll i = old_max + 1; i <= a; i++) {
            fac_cache[i] = fac_cache[i-1] * i % p;
        }
        invfac_cache[a] = invll(fac_cache[a]);
        for (ll i = a-1; i > old_max; i--) {
            invfac_cache[i] = invfac_cache[i+1] * (i + 1) % p;
        }
    }
}

inline ll    facll(ll a) { make_fac_cache(a); return fac_cache[a]; }
inline ll invfacll(ll a) { make_fac_cache(a); return invfac_cache[a]; }
inline bool isoutll(ll n, ll r) { return n < 0 || r < 0 || n < r; }
inline ll nPr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p; }
inline ll nCr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p * invfacll(r) % p; }

// 行列累乗; 1e9+7で割ったあまりを求めたい場合は適宜コメントアウトを解除

// 単位行列; idtm<型>(大きさ)
template<typename T>
vector<vector<T>> idtm(const size_t n) {
    vector<vector<T>> r(n, vector<T>(n, 0));
    REP(i, n) r[i][i] = 1;
    return r;
}

// 行列の積
template<typename T>
vector<vector<T>> mltm(const vector<vector<T>> &a, const vector<vector<T>> &b) {
    ull m = a.size(), q = b.size(), r = b[0].size();
    vector<vector<T>> c(m, vector<T>(r, (T)0));
    REP(i, m) REP(j, r) {
        REP(k, m) {
            // c[i][j] += a[i][k] * b[k][j];
            c[i][j] += a[i][k] * b[k][j] % p; c[i][j] %= p;
        }
    }
    return c;
}

// 行列の累乗
template<typename T>
vector<vector<T>> powm(const vector<vector<T>> &a, const ll n) {
    if (n == 0) {
        return idtm<T>(a.size());
    } else if (n == 1) {
        return a;
    } else if (n % 2 == 0) {
        vector<vector<T>> t = powm(a, n/2);
        return mltm(t, t);
    } else {
        vector<vector<T>> t = powm(a, n/2);
        return mltm(mltm(t, t), a);
    }
}

// 処理内容
int main() {

    clock_t sclk = clock();
    
    ll n, m, k, pp, q; cin >> n >> m >> k >> pp >> q;
    vector<ll> b(n);
    REP(i, n) cin >> b[i];

    ll bmlk = 0, bktc = 0;
    REP(i, n) {
        if (i < m){
            bmlk += b[i];
            bmlk %= p;
        } else {
            bktc += b[i];
            bktc %= p;
        }
    }

    ll pq2 = pp * invll(q) % p * 2 % p;

    ll half = invll(2);
    ll term = (1 + p - pq2) % p;
    ll pmlk = (1 + powll(term, k)    ) % p * half % p;
    ll pktc = (1 - powll(term, k) + p) % p * half % p;
    
    // DUMP(n);
    // DUMP(m);
    // DUMP(k);
    // DUMP(pp);
    // DUMP(q);
    // DUMP(bmlk);
    // DUMP(bktc);
    // DUMP(pq2);
    // DUMP(pmlk);
    // DUMP(pktc);

    cout << (bmlk * pmlk % p + bktc * pktc % p) % p << endl;

    cerr << "[DEBUG] Done in " << (double)(clock() - sclk) / CLOCKS_PER_SEC * 1e3 << " ms" << endl;
    
}
0