結果
問題 | No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率 |
ユーザー | mkawa2 |
提出日時 | 2021-06-12 00:10:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 996 ms / 2,000 ms |
コード長 | 2,217 bytes |
コンパイル時間 | 510 ms |
コンパイル使用メモリ | 82,356 KB |
実行使用メモリ | 81,344 KB |
最終ジャッジ日時 | 2024-12-15 04:18:57 |
合計ジャッジ時間 | 14,639 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
53,176 KB |
testcase_01 | AC | 43 ms
61,404 KB |
testcase_02 | AC | 92 ms
76,540 KB |
testcase_03 | AC | 41 ms
61,420 KB |
testcase_04 | AC | 49 ms
66,792 KB |
testcase_05 | AC | 40 ms
61,960 KB |
testcase_06 | AC | 44 ms
62,756 KB |
testcase_07 | AC | 43 ms
63,024 KB |
testcase_08 | AC | 39 ms
60,636 KB |
testcase_09 | AC | 44 ms
64,344 KB |
testcase_10 | AC | 43 ms
63,608 KB |
testcase_11 | AC | 48 ms
64,872 KB |
testcase_12 | AC | 41 ms
61,192 KB |
testcase_13 | AC | 232 ms
77,240 KB |
testcase_14 | AC | 165 ms
76,616 KB |
testcase_15 | AC | 107 ms
76,576 KB |
testcase_16 | AC | 127 ms
76,572 KB |
testcase_17 | AC | 125 ms
76,164 KB |
testcase_18 | AC | 121 ms
76,680 KB |
testcase_19 | AC | 78 ms
76,340 KB |
testcase_20 | AC | 556 ms
79,712 KB |
testcase_21 | AC | 103 ms
76,284 KB |
testcase_22 | AC | 41 ms
62,012 KB |
testcase_23 | AC | 963 ms
81,120 KB |
testcase_24 | AC | 960 ms
80,984 KB |
testcase_25 | AC | 996 ms
81,096 KB |
testcase_26 | AC | 977 ms
81,012 KB |
testcase_27 | AC | 962 ms
80,908 KB |
testcase_28 | AC | 971 ms
81,024 KB |
testcase_29 | AC | 957 ms
80,940 KB |
testcase_30 | AC | 952 ms
81,344 KB |
testcase_31 | AC | 965 ms
80,892 KB |
testcase_32 | AC | 966 ms
81,172 KB |
testcase_33 | AC | 989 ms
80,952 KB |
testcase_34 | AC | 100 ms
76,420 KB |
testcase_35 | AC | 99 ms
76,420 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 md = 998244353 # md = 10**9+7 def dot(aa, bb): h, w = len(aa), len(bb[0]) res = [[0]*w for _ in range(h)] for i, row in enumerate(aa): for j, col in enumerate(zip(*bb)): val = 0 for a, b in zip(row, col): val = (val+a*b)%md res[i][j] = val return res ma, na, s = LI() mb, nb, t = LI() K = II() s += t s, t = t, s pa = ma*pow(na, md-2, md) pb = mb*pow(nb, md-2, md) # print(pa,pb) dtop = [0]*(t+1) now = (1-pa)%md for i in range(t+1): dtop[i] = now now = now*pa%md pp0 = [[0]*(t+1) for _ in range(t+1)] for i in range(1, t): p = 1 d = 0 for j in range(i, t): pp0[i][j] = dtop[d] p -= dtop[d] d += 1 pp0[i][t] = p%md # p2D(pp0) dtop = [0]*(t+1) now = (1-pb)%md for i in range(t+1): dtop[i] = now now = now*pb%md pp1 = [[0]*(t+1) for _ in range(t+1)] for i in range(t-1, 0, -1): p = 1 d = 0 for j in range(i, 0, -1): pp1[i][j] = dtop[d] p -= dtop[d] d += 1 pp1[i][0] = p%md base = [[0]*(t+1) for _ in range(t+1)] for i in range(1, t): for j in range(i, t): for k in range(j+1): base[k][i] += pp0[i][j]*pp1[j][k] base[k][i] %= md for i in range(1, t): base[t][i] = pp0[i][t] base[0][0] = 1 base[t][t] = 1 # p2D(base) cc = [[0]*(t+1) for _ in range(t+1)] for i in range(t+1): cc[i][i] = 1 while K: if K & 1: cc = dot(cc, base) base = dot(base, base) K >>= 1 # print(s,t) # p2D(cc) print(cc[t][s]) print(cc[0][s])