結果

問題 No.995 タピオカオイシクナーレ
ユーザー goto_isyukugoto_isyuku
提出日時 2020-02-21 23:15:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 3,059 bytes
コンパイル時間 2,112 ms
コンパイル使用メモリ 173,676 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 09:17:51
合計ジャッジ時間 3,359 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;

typedef long long ll;

class ModInt{
public:
    long long n;
    int p;

    ModInt(){
    }

    //値と割る値を受け取って、オブジェクトを返す
    ModInt(long long _n, int _p){
        p = _p;
        n = _n % _p;

        //負の値を受け取ったときには正の値に戻す
        if(n < 0){
            n += p;
        }
    }

    ModInt operator+(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n += a.n;

        if(tmp.n > tmp.p){
            tmp.n -= tmp.p;
        }
        
        return tmp;
    }

    ModInt operator-(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n -= a.n;

        if(tmp.n < 0){
            tmp.n += tmp.p;
        }

        return tmp;
    }

    ModInt operator*(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = (tmp.n * a.n) % tmp.p;

        return tmp;
    }

    int modpow(int b, int k){
        if(k == 0){
            return 1;
        }else if(k % 2 == 1){
            long long tmp = b;
            tmp = tmp * modpow(b, k - 1) % p;
            
            return tmp;
        }else{
            long long tmp = modpow(b, k / 2);
            return tmp * tmp % p;
        }
    }

    int modinv(int b){
        return modpow(b, p - 2);
    }

    ModInt operator/(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = tmp.n * modinv(a.n) % tmp.p;
        return tmp;
    }
};

int main(){

    ll n,m,k,p,q;
    cin >> n >> m >> k >> p >> q;

    vector<ll> taste;

    rep(i, n){
        ll b;
        cin >> b;

        taste.pback(b);
    }

    vector<pair<ModInt, ModInt>> pv;

    pv.pback(mpair(ModInt(1, MODN), ModInt(0 , MODN)));
    pv.pback(mpair(ModInt(1, MODN) - ModInt(2, MODN) * ModInt(p, MODN) / ModInt(q, MODN), ModInt(p, MODN) / ModInt(q, MODN)));

    rep(i, ceil(log2(k))){
        ModInt a = pv[i + 1].first;
        ModInt b = pv[i + 1].second;
        pv.pback(mpair(a * a,a * b + b));
    }

    function<ModInt(pair<ModInt, ModInt>, ModInt)> f = [&](pair<ModInt, ModInt> a, ModInt x) ->ModInt{

        return a.first * x + a.second;

    };

    ModInt m_evenp = ModInt(1, MODN);

    while(k > 0){

        ll tmp = floor(log2(k) + EPS);

        cerr << k << " " << tmp << endl;

        if(k == 1){
            m_evenp = f(pv[1], m_evenp);
            break;
        }

        m_evenp = f(pv[tmp + 1], m_evenp);

        k = k - (ll)pow(2.0, tmp);

        
    }

    cerr << m_evenp.n << endl;

    ModInt oddp = ModInt(1, MODN) - m_evenp;

    ModInt ans = ModInt(0, MODN);

    rep(i,m){
        ans = ans + m_evenp * ModInt(taste[i], MODN);
    }

    rep(i, n - m){
        ans = ans + oddp * ModInt(taste[i + m], MODN);
    }

    cout << ans.n << endl;




    
    return 0;
}
0