結果

問題 No.995 タピオカオイシクナーレ
ユーザー ocatocat
提出日時 2020-02-22 02:10:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,743 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 174,116 KB
実行使用メモリ 20,224 KB
最終ジャッジ日時 2024-04-17 16:55:28
合計ジャッジ時間 5,223 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 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 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    ll get() const { return x; }
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); return (t & 1) ? a*a*(*this) : a*a; }
    operator ll () const { return x; }
    operator string () const { return to_string(x); }

    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};

template<class T>
class Matrix {
public:
    int r, c;
    vector<vector<T>> A;
    Matrix(int r, int c): r(r), c(c) { A.resize(r); for (int i=0; i<r; ++i) A[i].resize(c, 0); }
    Matrix &operator=(const Matrix &B) { tie(A, r, c) = make_tuple(B.A, B.r, B.c); return (*this); }
    const vector<T> &operator[](int i) const { return (A.at(i)); }
    vector<T> &operator[](int i) { return (A.at(i)); }
    Matrix &operator+=(const Matrix &B) { for (int i=0; i<r; ++i) for (int j=0; j<c; ++j) A[i][j] += B[i][j]; return (*this); }
    Matrix &operator-=(const Matrix &B) { for (int i=0; i<r; ++i) for (int j=0; j<c; ++j) A[i][j] -= B[i][j]; return (*this); }
    Matrix &operator*=(T k) { for (int i=0; i<r; ++i) for (int j=0; j<c; ++j) A[i][j] *= k; return (*this); }
    Matrix &operator*=(const Matrix &B) { vector<vector<T>> t(r, vector<T>(B.c, 0)); for (int i=0; i<r; ++i) for (int j=0; j<B.c; ++j) for (int k=0; k<c; ++k) t[i][j] += A[i][k] * B[k][j]; swap(A, t); return (*this); }
    Matrix &operator^=(ll k) { Matrix t(r, r); for (int i=0; i<r; ++i) t[i][i] = 1; for (; k; k>>=1) { if (k & 1) t *= (*this); (*this) *= (*this); } swap(A, t.A); return (*this); }
};

int main() {
    int N, M;
    ll K, _p, _q;
    cin >> N >> M >> K >> _p >> _q;
    mint p(_p), q(_q);

    Matrix<mint> B(N+1, 1);
    ll b;
    for (int i=1; i<=N; ++i) {
        cin >> b;
        B[i][0] = b;
    }

    Matrix<mint> A(1, N+1);
    for (int i=0; i<=M; ++i) A[0][i] = 1;

    Matrix<mint> C(N+1, N+1);
    C[0][0] = 1;
    for (int i=1; i<=N; ++i) {
        C[0][i] = p/q;
        C[i][i] = (q - mint(2) * p) / q;
    }
    C ^= K;
    (A *= C) *= B;
    cout << A[0][0] << endl;

    return 0;
}
0