結果

問題 No.995 タピオカオイシクナーレ
ユーザー buey_tbuey_t
提出日時 2023-03-28 15:00:27
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,697 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 81,560 KB
実行使用メモリ 256,252 KB
最終ジャッジ日時 2023-10-20 09:21:28
合計ジャッジ時間 13,632 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
    from heapq import heapify, heappop, heappush
    from bisect import bisect_left, bisect_right
    from copy import deepcopy
    import copy
    import random
    from collections import deque,Counter,defaultdict
    from itertools import permutations,combinations
    from decimal import Decimal,ROUND_HALF_UP
    #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    from functools import lru_cache, reduce
    #@lru_cache(maxsize=None)
    from operator import add,sub,mul,xor,and_,or_,itemgetter
    INF = 10**18
    mod1 = 10**9+7
    mod2 = 998244353
    
    #DecimalならPython
    #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    #p = のところを変更すること。
    #limitationも必要なら変更
    def nCr(n, r, p):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n-r] % p
    
    p = mod1
    limitation = 10 ** 6  # N は必要分だけ用意する
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用
    
    for i in range(2, limitation + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    
    def matmul(A,B,mod):
        res = [[0]*len(B[0]) for _ in [None]*len(A)]
        for i, resi in enumerate(res):
            for k, aik in enumerate(A[i]):
                for j,bkj in enumerate(B[k]):
                    resi[j] += aik*bkj
                    resi[j] %= mod
        return res
    
    def matpow(A,p,mod):
        if p%2:
            return matmul(A, matpow(A,p-1,mod),mod)
        elif p > 0:
            b = matpow(A,p//2,mod)
            return matmul(b,b,mod)
        else:
            return [[int(i==j) for j in range(len(A))] for i in range(len(A))]
    
    '''
    入れ替えるのか
    いや、確率p/qで全部が入れ替わるかもしれないのか
    確率は前計算

    '''

    N,M,K,p,q = map(int, input().split())
    
    P = p*pow(q,mod1-2,mod1)
    
    A = [[1-P,P],[P,1-P]]
    
    ls = matpow(A,K,mod1)
    
    tea = ls[0][0]
    kit = ls[0][1]
    
    ans = 0
    for i in range(N):
        b = int(input())
        
        if i < M:
            ans += b*tea
        else:
            ans += b*kit
        ans %= mod1
    
    print(ans)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0