結果

問題 No.298 話の伝達
ユーザー rpy3cpprpy3cpp
提出日時 2015-11-07 02:41:40
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 929 ms / 5,000 ms
コード長 842 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 86,748 KB
実行使用メモリ 77,024 KB
最終ジャッジ日時 2023-10-11 14:55:33
合計ジャッジ時間 4,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,264 KB
testcase_01 AC 75 ms
71,392 KB
testcase_02 AC 72 ms
70,896 KB
testcase_03 AC 72 ms
71,220 KB
testcase_04 AC 71 ms
71,276 KB
testcase_05 AC 382 ms
76,496 KB
testcase_06 AC 85 ms
75,960 KB
testcase_07 AC 71 ms
71,120 KB
testcase_08 AC 72 ms
71,064 KB
testcase_09 AC 85 ms
75,812 KB
testcase_10 AC 107 ms
76,996 KB
testcase_11 AC 137 ms
76,860 KB
testcase_12 AC 100 ms
76,424 KB
testcase_13 AC 134 ms
76,720 KB
testcase_14 AC 121 ms
77,024 KB
testcase_15 AC 72 ms
71,196 KB
testcase_16 AC 929 ms
76,760 KB
testcase_17 AC 97 ms
76,632 KB
testcase_18 AC 259 ms
76,760 KB
testcase_19 AC 71 ms
71,240 KB
testcase_20 AC 487 ms
76,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, M = map(int, input().split())
    Cs = [[] for i in range(N)]
    for m in range(M):
        src, dst, c = map(int, input().split())
        Cs[dst].append((src, c/100))
    return N, M, Cs

def solve(N, M, Cs):
    vs = [v for v in range(1, N)]
    vs.sort(key=lambda v: len(Cs[v]))
    prob = 0
    for on_off in range(1 + (1 << (N - 1)), 1 << N, 2):
        prob += calc_prob(on_off, vs, Cs)
    return prob

def calc_prob(on_off, vs, Cs):
    prob = 1
    for v in vs:
        if prob == 0:
            return 0
        p_off = 1
        for u, c in Cs[v]:
            if not on_off & (1 << u):
                continue
            p_off *= (1 - c)
        if on_off & (1 << v):
            prob *= (1 - p_off)
        else:
            prob *= p_off
    return prob

N, M, Cs = read_data()
print(solve(N, M, Cs))
0