結果

問題 No.995 タピオカオイシクナーレ
ユーザー hiro71687khiro71687k
提出日時 2023-04-16 18:23:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,232 bytes
コンパイル時間 3,991 ms
コンパイル使用メモリ 254,072 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 06:22:16
合計ジャッジ時間 5,658 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=1444999999;
ll mod=1000000007;
ll modpow(ll x, ll n) {
  x = x%mod;
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
    return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
int main(){
    ll n,m,k,p,q;
    cin >> n >> m >> k >> p >> q;
    vector<ll>c(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> c[i];
    }
    ll a=p;
    ll b=q-p;
    ll x=modpow((a+b)%mod,k);
    ll y=modpow((b-a+mod)%mod,k);
    ll ans=0;
    ll qq=inv_mod(modpow(q,k),mod);
    for (ll i = 0; i < m; i++)
    {
        ll xx=x+y;
        xx%=mod;
        xx*=qq;
        xx%=mod;
        xx*=inv_mod(2,mod);
        xx%=mod;
        xx*=c[i];
        xx%=mod;
        ans+=xx;
        ans%=mod;
    }
    for (ll i = m; i < n; i++)
    {
        ll xx=x-y+mod;
        xx%=mod;
        xx*=qq;
        xx%=mod;
        xx*=inv_mod(2,mod);
        xx%=mod;
        xx*=c[i];
        xx%=mod;
        ans+=xx;
        ans%=mod;
    }
    cout << ans << endl;
}
0