結果

問題 No.995 タピオカオイシクナーレ
ユーザー koi_kotyakoi_kotya
提出日時 2020-02-21 22:28:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,717 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 169,596 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:09:31
合計ジャッジ時間 2,996 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 41 ms
5,376 KB
testcase_17 AC 40 ms
5,376 KB
testcase_18 AC 40 ms
5,376 KB
testcase_19 AC 42 ms
5,376 KB
testcase_20 AC 42 ms
5,376 KB
testcase_21 AC 42 ms
5,376 KB
testcase_22 AC 43 ms
5,376 KB
testcase_23 AC 41 ms
5,376 KB
testcase_24 AC 41 ms
5,376 KB
testcase_25 AC 41 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

vector<vector<ll>> prod(vector<vector<ll>>& a, vector<vector<ll>>& b) {
    vector<vector<ll>> ret(a.size(),vector<ll>(b[0].size(),0));
    for (int i = 0;i < a.size();++i) for (int j = 0;j < b[0].size();++j) for (int k = 0;k < a[0].size();++k) {
        (ret[i][j] += a[i][k]*b[k][j]%mod) %= mod;
    }
    return ret;
}

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

int main() {
    int n,m;
    ll k,p,q;
    cin >> n >> m >> k >> p >> q;
    vector<vector<ll>> c(2,vector<ll>(2)),a(2,vector<ll>(1));
    for (int i = 0;i < n;++i) {
        int b;
        cin >> b;
        if (i < m) (a[1][0] += b) %= mod;
        else (a[0][0] += b) %= mod;
    }
    c[0][1] = c[1][0] = p*pow_mod(q,-1)%mod;
    c[0][0] = c[1][1] = (1-c[0][1]+mod)%mod;
    while (k) {
        if (k&1) a = prod(c,a);
        c = prod(c,c);
        k >>= 1;
    }
    cout << a[1][0] << endl;
}
0