結果

問題 No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率
ユーザー 👑 KazunKazun
提出日時 2021-04-10 04:39:28
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 516 ms / 2,000 ms
コード長 1,733 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2023-08-21 13:10:54
合計ジャッジ時間 10,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,292 KB
testcase_01 AC 76 ms
76,260 KB
testcase_02 AC 99 ms
76,264 KB
testcase_03 AC 77 ms
75,992 KB
testcase_04 AC 79 ms
76,064 KB
testcase_05 AC 77 ms
76,144 KB
testcase_06 AC 77 ms
76,032 KB
testcase_07 AC 78 ms
76,156 KB
testcase_08 AC 77 ms
76,248 KB
testcase_09 AC 79 ms
76,200 KB
testcase_10 AC 78 ms
76,148 KB
testcase_11 AC 79 ms
76,212 KB
testcase_12 AC 79 ms
76,200 KB
testcase_13 AC 169 ms
76,932 KB
testcase_14 AC 143 ms
77,028 KB
testcase_15 AC 110 ms
76,516 KB
testcase_16 AC 124 ms
77,140 KB
testcase_17 AC 126 ms
77,004 KB
testcase_18 AC 122 ms
77,136 KB
testcase_19 AC 91 ms
76,288 KB
testcase_20 AC 327 ms
77,228 KB
testcase_21 AC 109 ms
76,540 KB
testcase_22 AC 77 ms
76,320 KB
testcase_23 AC 511 ms
78,068 KB
testcase_24 AC 511 ms
78,080 KB
testcase_25 AC 515 ms
77,992 KB
testcase_26 AC 510 ms
77,956 KB
testcase_27 AC 516 ms
77,928 KB
testcase_28 AC 510 ms
78,072 KB
testcase_29 AC 510 ms
77,944 KB
testcase_30 AC 509 ms
77,992 KB
testcase_31 AC 510 ms
77,992 KB
testcase_32 AC 508 ms
77,996 KB
testcase_33 AC 509 ms
77,904 KB
testcase_34 AC 120 ms
76,488 KB
testcase_35 AC 121 ms
76,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#行列の乗算
def mul(A,B):
    size=len(A)
    C=[[0]*(size+1) for _ in range(size)]

    for i in range(size):
        for j in range(size):
            for k in range(size):
                C[i][j]+=(A[i][k]*B[k][j])%Mod
            C[i][j]%=Mod
    return C

#行列の累乗
def power(A,k):
    size=len(A)
    E=[[1 if y==x else 0 for y in range(size)] for x in range(size)]
    while k:
        if k&1:
            E=mul(E,A)
        A=mul(A,A)
        k>>=1
    return E

#========================
#===入力
MA,NA,S=map(int,input().split())
MB,NB,T=map(int,input().split())
K=int(input())

#===定数の設定
Mod=998244353
rho_A=(MA*pow(NA,Mod-2,Mod))%Mod
rho_B=(MB*pow(NB,Mod-2,Mod))%Mod

#===Aについての行列
U=[[0]*(S+T+1) for _ in range(S+T+1)]
for y in range(S+T+1):
    for x in range(S+T+1):
        if x==0:
            U[y][x]=1 if y==0 else 0
        elif x==S+T:
            U[y][x]=1 if y==S+T else 0
        else:
            if y<x:
                U[y][x]=0
            else:
                if y==S+T:
                    U[y][x]=pow(rho_A,y-x,Mod)
                else:
                    U[y][x]=(pow(rho_A,y-x,Mod)*(1-rho_A))%Mod

#===Bについての行列
V=[[0]*(S+T+1) for _ in range(S+T+1)]
for y in range(S+T+1):
    for x in range(S+T+1):
        if x==0:
            V[y][x]=1 if y==0 else 0
        elif x==S+T:
            V[y][x]=1 if y==S+T else 0
        else:
            if y>x:
                V[y][x]=0
            else:
                if y==0:
                    V[y][x]=pow(rho_B,x-y,Mod)
                else:
                    V[y][x]=(pow(rho_B,x-y,Mod)*(1-rho_B))%Mod

#===行列の計算
M=mul(V,U)
E=power(M,K)

#===結果の出力
print(E[S+T][T],E[0][T],sep="\n")
0