結果

問題 No.995 タピオカオイシクナーレ
ユーザー misora192misora192
提出日時 2020-04-29 21:47:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,816 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 173,908 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 02:10:29
合計ジャッジ時間 3,764 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

typedef vector<vector<ll>> mat;

void print(mat A){
	rep(i, A.size()){
		rep(j, A[i].size()){
			cout << A[i][j] << (j == A[i].size()-1 ? "\n" : " ");
		}
	}
}

mat mmul(mat A, mat B){
	int n = A.size();
	int l = A[0].size();
	int m = B[0].size();
	mat C(n, vector<ll>(m, 0));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			for(int k = 0; k < l; k++){
				C[i][j] += A[i][k] * B[k][j];
				C[i][j] %= MOD;
			}
		}
	}

	return C;
}

mat mE(int n){
	mat A(n, vector<ll>(n, 0));
	for(int i = 0; i < n; i++){
		A[i][i] = 1LL;
	}

	return A;
}

mat mpow(mat A, ll x){
	int n = A.size();
	if(x == 0) return mE(n);
	if(x % 2 == 1) return mmul(A, mpow(A, x - 1));

	mat B = mpow(A, x / 2);
	return mmul(B, B);
}

// pow
ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b & 1) {
		return a * pow(a, b - 1);
	} else {
	ll d = pow(a, b / 2);
	return d * d;
	}
}

// mod calc

ll powmod(ll a, ll b){
	if(b == 0) return 1;
	if(b & 1) {
		return a * powmod(a, b - 1) % MOD;
	} else {
		ll d = powmod(a, b / 2) % MOD;
		return d * d % MOD;
	}
}

ll sub(ll a, ll b){
	return a + MOD - b;
}

ll inv(ll a){
	return powmod(a, MOD - 2);
}


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

	ll n, m, k, p, q;
	cin >> n >> m >> k >> p >> q;

	vector<ll> b(n);
	rep(i, n) cin >> b[i];

	mat a(2, vector<ll>(2));
	a[0][0] = 1 + MOD - (p * inv(q)) % MOD;
	a[0][0] %= MOD;

	a[0][1] = (p * inv(q)) % MOD;
	a[1][0] = a[0][1];
	a[1][1] = a[0][0];

	mat c = mpow(a, k);
	ll x = c[0][0];
	ll y = c[0][1];

	ll ans = 0;
	for(int i = 0; i < m; i++){
		ans += x * b[i] % MOD;
		ans %= MOD;
	}

	for(int i = m; i < n; i++){
		ans += y * b[i] % MOD;
		ans %= MOD;
	}

	cout << ans << endl;
}
0