結果

問題 No.995 タピオカオイシクナーレ
ユーザー momoharamomohara
提出日時 2020-02-21 23:38:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 2,736 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 110,008 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 09:33:05
合計ジャッジ時間 2,478 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1LL;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll mod_inv(ll x, ll mod) {
	return mod_pow(x, mod - 2, mod);
}

Matrix mIdentity(ll n) {
	Matrix A(n, Array(n));
	for (int i = 0; i < n; ++i) A[i][i] = 1;
	return A;
}

Matrix mMul(const Matrix& A, const Matrix& B, ll mod) {
	Matrix C(A.size(), Array(B[0].size()));
	for (int i = 0; i < C.size(); ++i)
		for (int j = 0; j < C[i].size(); ++j)
			for (int k = 0; k < A[i].size(); ++k)
				(C[i][j] += (A[i][k] % mod) * (B[k][j] % mod)) %= mod;
	return C;
}
// O( n^3 log e )
Matrix mPow(const Matrix& A, ll e, ll mod) {
	return e == 0 ? mIdentity(A.size()) :
		e % 2 == 0 ? mPow(mMul(A, A, mod), e / 2, mod) : mMul(A, mPow(A, e - 1, mod), mod);
}

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

	ll n, m, k, p, q;
	cin >> n >> m >> k >> p >> q;
	ll pq = (p * mod_inv(q, MOD))%MOD;
	ll pq_ = (1 - pq + MOD) % MOD;

	Matrix x(2, Array(2, pq));
	REP(i, 2) x[i][i] = pq_;

	Matrix f = mPow(x, k, MOD);

	ll ans = 0;
	REP(i, m) {
		ll b;
		cin >> b;
		Matrix dp0({ {b},{0} });
		Matrix dp = mMul(f,dp0,MOD);
		(ans += dp[0][0]) %= MOD;
	}

	rep(i, m, n) {
		ll b;
		cin >> b;
		Matrix dp0({ {0},{b} });
		Matrix dp = mMul(f, dp0, MOD);
		(ans += dp[0][0]) %= MOD;
	}
	cout << ans << en;

	return 0;
}
0