結果
問題 | No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率 |
ユーザー | mkawa2 |
提出日時 | 2021-06-11 23:40:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,549 ms / 2,000 ms |
コード長 | 2,043 bytes |
コンパイル時間 | 460 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 83,120 KB |
最終ジャッジ日時 | 2024-12-15 03:23:24 |
合計ジャッジ時間 | 22,133 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,896 KB |
testcase_01 | AC | 54 ms
65,712 KB |
testcase_02 | AC | 149 ms
76,812 KB |
testcase_03 | AC | 52 ms
64,336 KB |
testcase_04 | AC | 68 ms
72,840 KB |
testcase_05 | AC | 53 ms
63,960 KB |
testcase_06 | AC | 55 ms
66,276 KB |
testcase_07 | AC | 56 ms
66,128 KB |
testcase_08 | AC | 46 ms
61,096 KB |
testcase_09 | AC | 64 ms
68,704 KB |
testcase_10 | AC | 56 ms
66,376 KB |
testcase_11 | AC | 68 ms
73,120 KB |
testcase_12 | AC | 50 ms
63,644 KB |
testcase_13 | AC | 379 ms
78,296 KB |
testcase_14 | AC | 287 ms
78,472 KB |
testcase_15 | AC | 181 ms
77,064 KB |
testcase_16 | AC | 228 ms
77,280 KB |
testcase_17 | AC | 225 ms
78,088 KB |
testcase_18 | AC | 220 ms
77,660 KB |
testcase_19 | AC | 129 ms
77,076 KB |
testcase_20 | AC | 931 ms
80,464 KB |
testcase_21 | AC | 182 ms
77,776 KB |
testcase_22 | AC | 55 ms
66,700 KB |
testcase_23 | AC | 1,538 ms
82,692 KB |
testcase_24 | AC | 1,545 ms
82,888 KB |
testcase_25 | AC | 1,528 ms
82,844 KB |
testcase_26 | AC | 1,537 ms
82,860 KB |
testcase_27 | AC | 1,541 ms
83,024 KB |
testcase_28 | AC | 1,540 ms
82,780 KB |
testcase_29 | AC | 1,531 ms
83,120 KB |
testcase_30 | AC | 1,530 ms
83,116 KB |
testcase_31 | AC | 1,549 ms
82,976 KB |
testcase_32 | AC | 1,547 ms
82,884 KB |
testcase_33 | AC | 1,536 ms
83,000 KB |
testcase_34 | AC | 157 ms
76,940 KB |
testcase_35 | AC | 154 ms
77,272 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): return [[sum(a*b%md for a, b in zip(row, col))%md for col in zip(*bb)] for row in aa] 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 for i in range(K.bit_length()): if K >> i & 1: cc = dot(cc, base) base = dot(base, base) # print(s,t) # p2D(cc) print(cc[t][s]) print(cc[0][s])