結果

問題 No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率
ユーザー convexineqconvexineq
提出日時 2021-06-11 23:05:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,436 ms / 2,000 ms
コード長 1,184 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 86,796 KB
実行使用メモリ 88,392 KB
最終ジャッジ日時 2023-08-21 13:57:00
合計ジャッジ時間 21,548 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,296 KB
testcase_01 AC 77 ms
76,144 KB
testcase_02 AC 131 ms
76,824 KB
testcase_03 AC 80 ms
75,892 KB
testcase_04 AC 79 ms
75,972 KB
testcase_05 AC 76 ms
75,708 KB
testcase_06 AC 75 ms
75,704 KB
testcase_07 AC 76 ms
75,496 KB
testcase_08 AC 77 ms
75,824 KB
testcase_09 AC 77 ms
75,848 KB
testcase_10 AC 75 ms
75,888 KB
testcase_11 AC 76 ms
75,944 KB
testcase_12 AC 76 ms
75,988 KB
testcase_13 AC 337 ms
79,756 KB
testcase_14 AC 238 ms
77,940 KB
testcase_15 AC 145 ms
76,844 KB
testcase_16 AC 186 ms
78,520 KB
testcase_17 AC 185 ms
77,080 KB
testcase_18 AC 180 ms
77,016 KB
testcase_19 AC 113 ms
76,312 KB
testcase_20 AC 831 ms
84,804 KB
testcase_21 AC 146 ms
76,752 KB
testcase_22 AC 76 ms
76,096 KB
testcase_23 AC 1,399 ms
88,392 KB
testcase_24 AC 1,431 ms
88,252 KB
testcase_25 AC 1,407 ms
88,384 KB
testcase_26 AC 1,377 ms
88,360 KB
testcase_27 AC 1,399 ms
88,116 KB
testcase_28 AC 1,412 ms
88,192 KB
testcase_29 AC 1,408 ms
88,228 KB
testcase_30 AC 1,414 ms
87,840 KB
testcase_31 AC 1,414 ms
88,228 KB
testcase_32 AC 1,436 ms
88,356 KB
testcase_33 AC 1,423 ms
88,248 KB
testcase_34 AC 154 ms
78,348 KB
testcase_35 AC 152 ms
78,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    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): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[int(i==j) for j in range(len(A))] for i in range(len(A))]

MOD = 998244353
m,n,s = map(int,input().split())
p = m*pow(n,MOD-2,MOD)%MOD
m,n,t = map(int,input().split())
q = m*pow(n,MOD-2,MOD)%MOD

"""
[-t,...0,...,s]
offset = -t
"""
N = s+t+1
N2 = 2*N

A = [[0]*N2 for _ in range(N2)]
A[0][N] = 1
for i in range(1,N):
    A[i][i+N] = v = 1-p
    for j in range(i+1,N):
        v = v*p%MOD
        A[i][j+N] = v
    A[i][N2-1] = pow(p,N-i-1,MOD)
    
B = [[0]*N2 for _ in range(N2)]
B[N2-1][N-1] = 1
for i in range(N-1):
    B[i+N][i] = v = 1-q
    for j in range(i)[::-1]:
        v = v*q%MOD
        B[i+N][j] = v
    B[i+N][0] = pow(q,i,MOD)

C = matmul(A,B)
C = matpow(C,int(input()))
v = C[t]
print(v[N-1]%MOD)
print(v[0]%MOD)
0