結果

問題 No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率
ユーザー 👑 KazunKazun
提出日時 2021-04-10 04:39:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 489 ms / 2,000 ms
コード長 1,733 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 77,108 KB
最終ジャッジ日時 2024-05-08 18:29:27
合計ジャッジ時間 8,747 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,608 KB
testcase_01 AC 48 ms
60,800 KB
testcase_02 AC 68 ms
66,944 KB
testcase_03 AC 46 ms
60,800 KB
testcase_04 AC 50 ms
61,312 KB
testcase_05 AC 47 ms
60,928 KB
testcase_06 AC 48 ms
60,544 KB
testcase_07 AC 49 ms
60,672 KB
testcase_08 AC 50 ms
60,288 KB
testcase_09 AC 48 ms
60,800 KB
testcase_10 AC 48 ms
61,056 KB
testcase_11 AC 50 ms
61,568 KB
testcase_12 AC 48 ms
60,672 KB
testcase_13 AC 145 ms
76,576 KB
testcase_14 AC 115 ms
76,288 KB
testcase_15 AC 82 ms
71,040 KB
testcase_16 AC 92 ms
73,856 KB
testcase_17 AC 95 ms
74,112 KB
testcase_18 AC 91 ms
72,960 KB
testcase_19 AC 62 ms
65,920 KB
testcase_20 AC 298 ms
76,288 KB
testcase_21 AC 78 ms
69,760 KB
testcase_22 AC 45 ms
60,416 KB
testcase_23 AC 485 ms
76,880 KB
testcase_24 AC 489 ms
76,672 KB
testcase_25 AC 488 ms
77,108 KB
testcase_26 AC 489 ms
76,928 KB
testcase_27 AC 485 ms
76,800 KB
testcase_28 AC 489 ms
76,672 KB
testcase_29 AC 489 ms
76,864 KB
testcase_30 AC 488 ms
76,800 KB
testcase_31 AC 485 ms
76,960 KB
testcase_32 AC 486 ms
76,812 KB
testcase_33 AC 487 ms
76,928 KB
testcase_34 AC 94 ms
69,760 KB
testcase_35 AC 91 ms
69,760 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