結果

問題 No.995 タピオカオイシクナーレ
ユーザー leaf_1415leaf_1415
提出日時 2020-02-21 22:12:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,831 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 63,684 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:06:32
合計ジャッジ時間 1,525 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

struct Matrix{
	int h, w;
	vector<llint> mat;
	Matrix(){
		h = w = 0;
	}
	Matrix(int h, int w){
		this->h = h, this->w = w;
		mat.resize(h*w);
	}
	llint& at(int i, int j){
		return mat[w*(i-1)+(j-1)];
	}
	static Matrix ident(int size){
		Matrix ret(size, size);
		for(int i = 1; i <= size; i++) ret.at(i, i) = 1;
		return ret;
	}
	Matrix operator*(Matrix& ope){
		Matrix ret(h, ope.w);
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= ope.w; j++){
				for(int k = 1; k <= w; k++){
					ret.at(i, j) += at(i, k) * ope.at(k, j) % mod;
					ret.at(i, j) %= mod;
				}
			}
		}
		return ret;
	}
	Matrix pow(llint n){
		if(n == 0) return ident(h);
		if(n % 2){
			return pow(n-1) * (*this);
		}
		else{
			Matrix tmp = pow(n/2);
			return tmp * tmp;
		}
	}
	void print(){
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cout << at(i, j) << " ";
			}
			cout << endl;
		}
	}
};

llint n, m, k, p, q;
llint b[100005];
Matrix mat;

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

  cin >> n >> m >> k >> p >> q;
  for(int i = 1; i <= n; i++) cin >> b[i];

  mat = Matrix(2, 2);
  llint P = p * modpow(q, mod-2) % mod;
  mat.at(1, 1) = mat.at(2, 2) = (1-P+mod) % mod;
  mat.at(1, 2) = mat.at(2, 1) = P;

  Matrix pmat = mat.pow(k);

  llint ans = 0, sum = 0;
  for(int i = 1; i <= m; i++) sum += b[i], sum %= mod;
  ans += sum * pmat.at(1, 1) % mod;

  sum = 0;
  for(int i = m+1; i <= n; i++) sum += b[i], sum %= mod;
  ans += sum * pmat.at(1, 2) % mod;
  ans %= mod;

  cout << ans << endl;

  return 0;
}
0