結果

問題 No.995 タピオカオイシクナーレ
ユーザー renjyaku_intrenjyaku_int
提出日時 2020-03-09 16:30:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,557 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 166,832 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 17:01:17
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int mod = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m,k;
ll p,q;
vector<ll> b;
struct matrix{
  ll a[70][70];
  matrix(){
      for (ll i = 0; i < 2; i++)
    {
        for(ll j=0;j<2;j++){
            a[i][j]=0;
        }
    }
  }
};
matrix mult(matrix a, matrix b){
  matrix c;
  for(ll i=0;i<2;i++){
    for(ll j=0;j<2;j++){
        for(ll k=0;k<2;k++)
        c.a[i][j]=(c.a[i][j]+(a.a[i][k]*b.a[k][j])%mod)%mod;
    }
  }
  return c;
}
matrix binpow(matrix a, ll b){
  matrix res;
  for(ll i=0;i<2;i++)res.a[i][i]=1;
  while(b){
    if(b&1)
      res=mult(res,a);
    b>>=1;
    a=mult(a,a);
  }
  return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m>>k>>p>>q;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        b.push_back(temp);
    }
    ll drink_sum=0;
    rep(i,m){
        drink_sum+=b[i];
    }
    ll kit_sum=0;
    for(int i=m;i<n;i++){
        kit_sum+=b[i];
    }
    matrix s;
    ll temp=modinv(q,mod);
    s.a[0][0]=(q-p)*temp;
    s.a[0][1]=p*temp;
    s.a[1][0]=p*temp;
    s.a[1][1]=(q-p)*temp;
    ll ans=0;
    binpow(s,k);
    ans+=s.a[0][0]*drink_sum;
    ans%=mod;
    ans+=s.a[0][1]*kit_sum;
    ans%=mod;
    cout << ans << "\n";
}
0