結果

問題 No.995 タピオカオイシクナーレ
ユーザー stngstng
提出日時 2022-08-17 15:46:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,400 KB
最終ジャッジ日時 2024-04-15 05:23:53
合計ジャッジ時間 3,479 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,608 KB
testcase_01 AC 37 ms
52,352 KB
testcase_02 AC 37 ms
52,864 KB
testcase_03 AC 37 ms
52,480 KB
testcase_04 AC 37 ms
52,352 KB
testcase_05 AC 37 ms
52,608 KB
testcase_06 AC 37 ms
52,480 KB
testcase_07 AC 37 ms
52,096 KB
testcase_08 AC 37 ms
52,096 KB
testcase_09 AC 37 ms
52,480 KB
testcase_10 AC 37 ms
52,352 KB
testcase_11 AC 45 ms
55,168 KB
testcase_12 AC 44 ms
55,040 KB
testcase_13 AC 43 ms
54,784 KB
testcase_14 AC 41 ms
53,504 KB
testcase_15 AC 44 ms
54,528 KB
testcase_16 AC 104 ms
77,208 KB
testcase_17 AC 104 ms
77,400 KB
testcase_18 AC 105 ms
77,312 KB
testcase_19 AC 104 ms
77,156 KB
testcase_20 AC 105 ms
77,056 KB
testcase_21 AC 104 ms
76,928 KB
testcase_22 AC 103 ms
77,204 KB
testcase_23 AC 104 ms
77,240 KB
testcase_24 AC 104 ms
76,868 KB
testcase_25 AC 103 ms
76,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 行列の乗算(mod)
def mat_mul(a, b):
    I, K, J = len(a), len(b), len(b[0])
    c = [[0 for j in range(J)] for i in range(I)]
    for i in range(I):
        for k in range(K):
            for j in range(J):
                c[i][j] += a[i][k] * b[k][j]
                c[i][j] %= mod
    return c

# 行列の累乗(mod)
def mat_pow(a, n):
    b = [[0 for j in range(len(a))] for i in range(len(a))]
    for i in range(len(a)):
        b[i][i] = 1
    while n > 0:
        if n & 1:
            b = mat_mul(b, a)
        a = mat_mul(a, a)
        n >>= 1
    return b

n,m,k,p,q = map(int,input().split())
b = [int(input()) for i in range(n)]

mod = 10**9+7

ans = 0
#n = 2

st = [[0]*2 for i in range(2)]
st[0][0] = q-p
st[0][1] = p
st[1][0] = p
st[1][1] = q-p
kk = mat_pow(st,k)
bo = pow(q,k,mod)
#print(kk)
#exit()
for i in range(n):
    if i <= m-1:
        ans += kk[0][0]*b[i]
    else:
        ans += kk[0][1]*b[i]
    #print(ans,i)
#print(ans,16)
#exit()
m = pow(bo,mod-2,mod)
print(ans*m%mod)
0