結果
| 問題 | No.995 タピオカオイシクナーレ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-07-15 09:40:35 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 568 ms / 2,000 ms | 
| コード長 | 772 bytes | 
| コンパイル時間 | 250 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 43,876 KB | 
| 最終ジャッジ日時 | 2024-09-16 17:55:15 | 
| 合計ジャッジ時間 | 17,745 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 | 
ソースコード
import sys
import numpy as np
input = sys.stdin.buffer.readline
MOD = 10 ** 9 + 7
modinv = lambda a, mod=MOD: pow(a, -1, mod)
def pow_matrix_mod(x, n, mod=MOD):
    x = x.astype(object)
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod
N, M, K, P, Q = map(int, input().split())
pq = P * modinv(Q) % MOD
matr = np.array([[(1 - pq) % MOD, pq], [pq, (1 - pq) % MOD]], dtype=np.int64)
tea = 0
kitchen = 0
for _ in range(M):
    tea += int(input())
for _ in range(N - M):
    kitchen += int(input())
tea %= MOD
kitchen %= MOD
ans = (np.array([tea, kitchen]) @ pow_matrix_mod(matr, K))[0]
ans %= MOD
print(ans)
            
            
            
        