結果

問題 No.995 タピオカオイシクナーレ
ユーザー outlineoutline
提出日時 2020-03-04 22:18:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 3,898 bytes
コンパイル時間 1,235 ms
コンパイル使用メモリ 116,640 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 01:55:25
合計ジャッジ時間 2,489 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-15;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_MOD() {return mod;}
};

using modint = ModInt<mod>;
using vec = vector<modint>;
using mat = vector<vec>;

mat mul(const mat& A, const mat& B){
    mat res = mat(A.size(), vec(B[0].size(), 0));
    for(int i = 0; i < A.size(); ++i){
        for(int k = 0; k < B.size(); ++k){
            for(int j = 0; j < B[0].size(); ++j){
                res[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    return res;
}

mat pow(mat A, ll n){
    mat res = mat(A.size(), vec(A[0].size(), 0));
    for(int i = 0; i < A.size(); ++i)   res[i][i] = 1;
    while(n > 0){
        if(n & 1)   res = mul(res, A);
        A = mul(A, A);
        n >>= 1;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    ll k;
    modint p, q;
    cin >> n >> m >> k >> p >> q;
    vector<modint> b(n);
    for(int i = 0; i < n; ++i)  cin >> b[i];
    mat P = mat(2, vec(2));
    P[0][0] = (modint)1 - p * q.inverse();
    P[1][1] = P[0][0];
    P[0][1] = p * q.inverse();
    P[1][0] = P[0][1];
    P = pow(P, k);
    modint p0 = P[0][0];
    modint p1 = P[0][1];
    modint res = 0;
    for(int i = 0; i < n; ++i){
        if(i < m){
            res += b[i] * p0;
        }
        else{
            res += b[i] * p1;
        }
    }
    cout << res << endl;
}
0