結果

問題 No.995 タピオカオイシクナーレ
ユーザー yakkiyakki
提出日時 2020-02-22 19:58:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 2,202 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 129,504 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 03:02:57
合計ジャッジ時間 2,883 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 2 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 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 44 ms
5,376 KB
testcase_17 AC 44 ms
5,376 KB
testcase_18 AC 44 ms
5,376 KB
testcase_19 AC 44 ms
5,376 KB
testcase_20 AC 44 ms
5,376 KB
testcase_21 AC 44 ms
5,376 KB
testcase_22 AC 43 ms
5,376 KB
testcase_23 AC 43 ms
5,376 KB
testcase_24 AC 44 ms
5,376 KB
testcase_25 AC 44 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

template<typename T>
struct Mat{
    vector<vector<T>> val;
    Mat(int n, int m, T x = 0) : val(n,vector<T>(m,x)){}
    void init(int n, int m, T x = 0){
        val.assign(n,vector<T>(m,x));
    }
    size_t size(){
        return val.size();
    }
    inline vector<T>& operator [](int i){
        return val[i];
    }
};

Mat<ll> operator *(Mat<ll> A, Mat<ll> B){
    Mat<ll> R(A.size(),B[0].size());
    for(int i = 0; i < A.size(); i++){
        for(int j = 0; j < B[0].size(); j++){
            for(int k = 0; k < B.size(); k++){
                R[i][j] += A[i][k]*B[k][j]+MOD;
                R[i][j] %= MOD;
            }
        }
    }
    return R;
}

Mat<ll> pow(Mat<ll> A, ll n){
    Mat<ll> R(A.size(),A.size());
    for(int i = 0; i < A.size(); i++) R[i][i] = 1;
    while(n > 0){
        if(n&1) R = R*A;
        A = A*A;
        n >>= 1;
    }
    return R;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main(){
	ll N,M,K,p,q; cin >> N >> M >> K >> p >> q;
	vector<ll> b(N);
	rep(i,N) cin >> b[i];
	Mat<ll> mt(2,2);
	mt[0][0] = mt[1][1] = (1-p*modinv(q,MOD)%MOD+MOD)%MOD;
	mt[0][1] = mt[1][0] = p*modinv(q,MOD)%MOD;
	Mat<ll> mt2 = pow(mt,K);
	ll ans = 0;
	rep(i,N){
		if(i <= M-1){
			ans += mt2[0][0]*b[i]%MOD;
			ans %= MOD;
		}
		else{
			ans += mt2[0][1]*b[i]%MOD;
			ans %= MOD;
		}
	}
	cout << ans << endl;

}

0