結果
問題 | No.995 タピオカオイシクナーレ |
ユーザー | oevl |
提出日時 | 2020-04-19 15:53:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 4,065 bytes |
コンパイル時間 | 2,455 ms |
コンパイル使用メモリ | 210,400 KB |
実行使用メモリ | 6,816 KB |
最終ジャッジ日時 | 2024-10-05 13:31:13 |
合計ジャッジ時間 | 3,850 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 37 ms
5,248 KB |
testcase_17 | AC | 36 ms
5,248 KB |
testcase_18 | AC | 37 ms
5,248 KB |
testcase_19 | AC | 37 ms
5,248 KB |
testcase_20 | AC | 38 ms
5,248 KB |
testcase_21 | AC | 38 ms
5,248 KB |
testcase_22 | AC | 37 ms
5,248 KB |
testcase_23 | AC | 36 ms
5,248 KB |
testcase_24 | AC | 37 ms
5,248 KB |
testcase_25 | AC | 38 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template<int64_t MOD> class ModInt { public: int64_t x; constexpr ModInt() : x(0) {} constexpr ModInt(int64_t v) : x((v % MOD + MOD) % MOD) {} constexpr ModInt operator - () const noexcept { return x ? MOD - x : 0;} constexpr ModInt operator + (const ModInt a) const noexcept { return ModInt(*this) += a;} constexpr ModInt operator - (const ModInt a) const noexcept { return ModInt(*this) -= a;} constexpr ModInt operator * (const ModInt a) const noexcept { return ModInt(*this) *= a;} constexpr ModInt operator / (const ModInt a) const noexcept { return ModInt(*this) /= a;} constexpr ModInt operator / (const int64_t a) const noexcept { return ModInt(*this) /= a;} constexpr ModInt operator += (const ModInt a) noexcept { x += a.x; if (x >= MOD) x -= MOD; return *this; } constexpr ModInt operator += (const int64_t a) noexcept { auto hs = ModInt<MOD>(a); (*this) += hs; return *this; } constexpr ModInt operator -= (const ModInt a) noexcept { if (x < a.x) x += MOD; x -= a.x; return *this; } constexpr ModInt operator -= (const int64_t a) noexcept { auto hs = ModInt<MOD>(a); (*this) -= hs; return *this; } constexpr ModInt operator *= (const ModInt a) noexcept { x = x * a.x % MOD; return *this; } constexpr ModInt operator *= (const int64_t a) noexcept { auto hs = ModInt<MOD>(a); (*this) *= hs; return *this; } constexpr ModInt &operator /= (ModInt a) noexcept { int64_t exp = MOD - 2; while (exp > 0) { if (exp & 1ul) *this *= a; a *= a; exp >>= 1ul; } return *this; } constexpr ModInt &operator /= (int64_t a) noexcept { auto hs = ModInt<MOD>(a); (*this) /= hs; return *this; } constexpr ModInt &operator ++ () noexcept { if (++x >= MOD) x -= MOD; return *this; } constexpr ModInt &operator -- () noexcept { if (x-- == 0) x += MOD; return *this; } constexpr bool operator < (const ModInt a) const noexcept { return x < a.x;} constexpr bool operator == (const ModInt a) const noexcept { return this->x == a.x;} constexpr bool operator != (const ModInt a) const noexcept { return !(*this == a);} friend istream &operator >> (istream &in, ModInt &m) { in >> m.x; if (m.x < 0) m.x += MOD; m.x %= MOD; return in; } friend ostream &operator << (ostream &out, const ModInt &p) { return out << p.x;} constexpr ModInt pow(int64_t p) const { ModInt ret(1); ModInt mul(x); while (p > 0) { if (p & 1ul) ret *= mul; mul *= mul; p >>= 1ul; } return ret; } }; const int64_t MOD = 1000000007LL; using mint = ModInt<MOD>; using vec = vector<mint>; using Matrix = vector<vec>; Matrix Mul(Matrix A, Matrix B) { Matrix C(A.size(), vec(B[0].size())); for(int i = 0; i < A.size(); ++i) { for(int k = 0; k < B.size(); ++k) { for(int j = 0; j < B[0].size(); ++j) { C[i][j] += (A[i][k] * B[k][j]); } } } return C; } Matrix Pow(Matrix A, int64_t n) { int N = A.size(); Matrix B(N, vec(N)); for(int i = 0; i < N; ++i) B[i][i] = 1; while(n > 0) { if(n & 1) B = Mul(B, A); A = Mul(A, A); n >>= 1; } return B; } int main() { int N, M, p, q; int64_t K; cin >> N >> M >> K >> p >> q; vector<int> b(N); for(auto &e : b) cin >> e; Matrix A(2, vec(2)); mint a = (mint)p / q; A[0][0] = (mint)-2 * a + 1; A[0][1] = a; A[1][0] = 0; A[1][1] = 1; A = Pow(A, K); mint ans = 0; mint P = A[0][0] + A[0][1]; for(int i = 0; i < N; ++i) { if(i < M) ans += P * b[i]; else ans += ((mint)1 - P) * b[i]; } cout << ans << '\n'; return 0; }