結果

問題 No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率
ユーザー ああいいああいい
提出日時 2022-03-15 21:57:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 1,577 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 81,548 KB
実行使用メモリ 76,148 KB
最終ジャッジ日時 2023-10-23 20:42:03
合計ジャッジ時間 10,102 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,276 KB
testcase_01 AC 46 ms
61,276 KB
testcase_02 AC 79 ms
72,992 KB
testcase_03 AC 45 ms
61,708 KB
testcase_04 AC 53 ms
64,040 KB
testcase_05 AC 46 ms
61,296 KB
testcase_06 AC 47 ms
61,756 KB
testcase_07 AC 48 ms
61,756 KB
testcase_08 AC 43 ms
59,500 KB
testcase_09 AC 48 ms
61,756 KB
testcase_10 AC 47 ms
61,756 KB
testcase_11 AC 51 ms
64,040 KB
testcase_12 AC 43 ms
61,268 KB
testcase_13 AC 152 ms
75,756 KB
testcase_14 AC 118 ms
75,528 KB
testcase_15 AC 82 ms
72,448 KB
testcase_16 AC 97 ms
73,920 KB
testcase_17 AC 96 ms
73,276 KB
testcase_18 AC 95 ms
73,288 KB
testcase_19 AC 69 ms
70,400 KB
testcase_20 AC 329 ms
75,744 KB
testcase_21 AC 83 ms
72,448 KB
testcase_22 AC 43 ms
59,516 KB
testcase_23 AC 542 ms
76,144 KB
testcase_24 AC 544 ms
76,140 KB
testcase_25 AC 544 ms
76,140 KB
testcase_26 AC 542 ms
76,140 KB
testcase_27 AC 542 ms
76,140 KB
testcase_28 AC 547 ms
76,144 KB
testcase_29 AC 541 ms
76,144 KB
testcase_30 AC 543 ms
76,140 KB
testcase_31 AC 543 ms
76,140 KB
testcase_32 AC 543 ms
76,148 KB
testcase_33 AC 541 ms
76,136 KB
testcase_34 AC 84 ms
68,276 KB
testcase_35 AC 86 ms
70,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

P = 998244353
m,n,S = map(int,input().split())
pa = m * pow(n,P-2,P) % P
qa = (1 - pa) % P
m,n,T = map(int,input().split())
pb = m * pow(n,P-2,P) % P
qb = (1 - pb) % P
K = int(input())
C = 205
SA = [0] * C
SB = [0] * C
now = qa
SA[0] = qa
for i in range(1,C):
    now = now * pa % P
    SA[i] = now
now = qb
SB[0] = now
for i in range(1,C):
    now = now * pb % P
    SB[i] = now

n = S + T + 1
def seki(x,y):
    l = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                l[i][j] = (l[i][j] + x[i][k] * y[k][j]) % P
    return l
e = [[0] * n for _ in range(n)]
for i in range(n):
    e[i][i] = 1
R = [[0] * n for _ in range(n)]
for j in range(-T,S+1):
    for i in range(-T,S+1):
        if i == S:
            if j != S:continue
            R[S-j][S-i] = 1
            continue
        if i == -T:
            if j != -T:continue
            R[S-j][S-i] = 1
            continue
        if j == S:
            tmp = pow(pa,S - i,P)
            R[S-j][S-i] = tmp
            continue
        if j == -T:
            tmp = 0
            for k in range(i,S):
                tmp += SA[k-i] * pow(pb,k-j,P) % P
                tmp %= P
            R[S-j][S-i] = tmp
            continue
        else:
            delta = max(i,j)
            tmp = 0
            for k in range(delta,S):
                tmp += SA[k-i] * SB[k - j] % P
                tmp %= P
            R[S-j][S-i] = tmp
while K:
    if K & 1:
        e = seki(e,R)
    R = seki(R,R)
    K >>= 1

a = e[0][S]
b = e[-1][S]

print(a)
print(b)
0