結果

問題 No.995 タピオカオイシクナーレ
ユーザー Y17Y17
提出日時 2020-02-21 22:23:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 2,689 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 159,584 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:08:52
合計ジャッジ時間 3,215 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 3 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 76 ms
5,376 KB
testcase_17 AC 76 ms
5,376 KB
testcase_18 AC 73 ms
5,376 KB
testcase_19 AC 72 ms
5,376 KB
testcase_20 AC 74 ms
5,376 KB
testcase_21 AC 75 ms
5,376 KB
testcase_22 AC 77 ms
5,376 KB
testcase_23 AC 75 ms
5,376 KB
testcase_24 AC 75 ms
5,376 KB
testcase_25 AC 71 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define M 1000000007 

template<int64_t MOD>
class ModInt {
    int64_t value;
public:
    // constructor
    inline ModInt(int64_t val = 0) noexcept :
        value((val >= MOD) ? (val % MOD) : (val < 0) ? ((val + MOD) % MOD) : val) {}

    // プリミティブ整数型へのキャスト (型の明示:必要)
    template<class Int>
    explicit inline operator Int() const noexcept { return static_cast<Int>(value); }

    inline ModInt inv() const noexcept {
        return ModInt<MOD>::pow(value, MOD-2);
    }

    inline ModInt& operator+=(ModInt x) noexcept {
        if ((value += x.value) >= MOD) value -= MOD;
        return *this;
    }
    inline ModInt& operator-=(ModInt x) noexcept {
        if ((value -= x.value) < 0) value += MOD;
        return *this;
    }
    inline ModInt& operator*=(ModInt x) noexcept {
        value = (value * x.value) % MOD; return *this;
    }
    inline ModInt& operator/=(ModInt x) noexcept {
        value = (value * x.inv().value) % MOD; return *this;
    }

    inline ModInt operator+(ModInt x) const noexcept { return ModInt(*this) += x; }
    inline ModInt operator-(ModInt x) const noexcept { return ModInt(*this) -= x; }
    inline ModInt operator*(ModInt x) const noexcept { return ModInt(*this) *= x; }
    inline ModInt operator/(ModInt x) const noexcept { return ModInt(*this) /= x; }
    inline bool operator==(ModInt x) const noexcept { return value == x.value; }
    inline bool operator!=(ModInt x) const noexcept { return !(this->operator==(x)); }

    friend ostream& operator<<(ostream &os, ModInt x) noexcept { os << x.value; return os; }
    friend istream& operator>>(istream &is, ModInt &x) noexcept { is >> x.value; return is; }

    static constexpr inline ModInt pow(int64_t n, int64_t p) noexcept {
        int64_t ret = 1;
        for(; p > 0; p >>= 1) {
            if (p & 1) ret = (ret * n) % MOD;
            n = (n * n) % MOD;
        }
        return ret;
    }

    ModInt p(int64_t p){
		int64_t n = value;
        int64_t ret = 1;
        for(; p > 0; p >>= 1) {
            if (p & 1) ret = (ret * n) % MOD;
            n = (n * n) % MOD;
        }
        return value = ret;
    }
};

using mint = ModInt<M>;

mint p, q;

mint func(int64_t x){
	mint tmp = 1;
	tmp /= 2;
	mint t2 = 1;
	t2 -= p*2/q;
	t2.p(x);
	t2 += 1;
	return tmp * t2; 
}

signed main(){
	int n, m;
	cin >> n >> m;

	int k;
	cin >> k;

	cin >> p >> q;

	mint b[100010];

	mint ans = 0;

	for(int i = 0;i < n;i++){
		cin >> b[i];
		if(i < m){
			ans += b[i] * func(k); 
		}else{
			ans += b[i] * ((mint)(1) - func(k)); 
		}
	}

	cout << ans << endl;

	return 0;
}
0