結果

問題 No.995 タピオカオイシクナーレ
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-16 13:56:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 79,024 KB
最終ジャッジ日時 2023-08-28 22:06:52
合計ジャッジ時間 5,499 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,376 KB
testcase_01 AC 78 ms
71,112 KB
testcase_02 AC 78 ms
71,112 KB
testcase_03 AC 73 ms
71,388 KB
testcase_04 AC 73 ms
71,432 KB
testcase_05 AC 73 ms
71,096 KB
testcase_06 AC 73 ms
71,240 KB
testcase_07 AC 74 ms
71,384 KB
testcase_08 AC 75 ms
71,112 KB
testcase_09 AC 71 ms
71,280 KB
testcase_10 AC 73 ms
71,444 KB
testcase_11 AC 81 ms
71,400 KB
testcase_12 AC 81 ms
71,292 KB
testcase_13 AC 79 ms
71,112 KB
testcase_14 AC 78 ms
71,360 KB
testcase_15 AC 80 ms
71,340 KB
testcase_16 AC 140 ms
79,024 KB
testcase_17 AC 130 ms
78,632 KB
testcase_18 AC 131 ms
78,768 KB
testcase_19 AC 138 ms
78,844 KB
testcase_20 AC 130 ms
78,996 KB
testcase_21 AC 130 ms
78,884 KB
testcase_22 AC 129 ms
78,812 KB
testcase_23 AC 131 ms
78,796 KB
testcase_24 AC 130 ms
78,876 KB
testcase_25 AC 127 ms
78,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
p/q
m,n<=10**5
m<=n
k<=10**12
各粒が最終的にミルクティーの中にいる確率を求め、足し上げる。
ミルクティー中、キッチンのタピオカそれぞれまとめて計算
行列積のダブリングでOK
A:v->v
v=(x,y) x:ミルクティー中、y:キッチン中
A=((1-p/q,p/q),(p/q,1-p/q))
"""
n,m,k,p,q=map(int,input().split())
b=[int(input()) for _ in range(n)]
mod=10**9+7

# 行列積
def dot(mtr0,mtr1):
  a,b=len(mtr0),len(mtr1[0])
  t=len(mtr0[0])
  if t!=len(mtr1):return None
  ret=[[0]*b for _ in range(a)]
  for i in range(a):
    for j in range(b):
      tmp=0
      for k in range(t):
        tmp+=mtr0[i][k]*mtr1[k][j]
        tmp%=mod
      ret[i][j]=tmp
  return ret
# 使用例
# mtr:演算行列
# dp:dp行列。初期値として単位行列
dp=[[sum(b[:m])],[sum(b[m:])]]
tmp=p*pow(q,mod-2,mod)%mod
mtr=[[(1-tmp)%mod,tmp],[tmp,(1-tmp)%mod]]
while k:
  if k&1:
    dp=dot(mtr,dp)
  k>>=1
  mtr=dot(mtr,mtr)
print(dp[0][0])
0