結果

問題 No.298 話の伝達
ユーザー convexineqconvexineq
提出日時 2021-01-02 15:27:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 809 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 96,580 KB
最終ジャッジ日時 2024-04-20 08:55:50
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
55,388 KB
testcase_01 AC 42 ms
54,816 KB
testcase_02 AC 36 ms
54,636 KB
testcase_03 AC 36 ms
54,332 KB
testcase_04 AC 36 ms
54,860 KB
testcase_05 AC 201 ms
96,368 KB
testcase_06 AC 45 ms
63,936 KB
testcase_07 AC 41 ms
55,192 KB
testcase_08 AC 35 ms
55,192 KB
testcase_09 AC 43 ms
64,396 KB
testcase_10 AC 49 ms
71,248 KB
testcase_11 AC 201 ms
96,516 KB
testcase_12 AC 126 ms
86,220 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 39 ms
54,256 KB
testcase_16 AC 209 ms
96,580 KB
testcase_17 AC 48 ms
67,564 KB
testcase_18 AC 86 ms
81,208 KB
testcase_19 AC 38 ms
54,648 KB
testcase_20 AC 132 ms
86,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
prob = [[0.0]*n for _ in range(n)]
g = [[] for _ in range(n)]
indegree = [0]*n
for _ in range(m):
    a,b,c = map(int,input().split())
    prob[a][b] = c/100
    g[a].append(b)
    indegree[b] += 1
from collections import deque
q = deque(i for i in range(n) if indegree[i]==0)
order = []
while q:
    i = q.popleft()
    order.append(i)
    for b in g[i]:
        indegree[b] -= 1
        if indegree[b]==0: q.append(b)
while order[0] != 0: order.pop(0)
n = len(order)
dp = [0.0,1.0]
for i in range(1,n):
    p = order[i]
    N = 1<<i
    ndp = [0.0]*(2*N)
    for mask in range(N):
        x = 1.0
        for j in range(i):
            x *= 1.0-(mask>>j&1)*prob[order[j]][p]
        ndp[mask] += dp[mask]*x
        ndp[mask+N] += dp[mask]*(1-x)
    dp = ndp
print(sum(dp[N:]))
0