結果

問題 No.298 話の伝達
ユーザー nebukuro09nebukuro09
提出日時 2017-04-02 19:01:02
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 2,626 ms
コンパイル使用メモリ 164,132 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 12:40:39
合計ジャッジ時間 3,950 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

alias Tuple!(int, "to", real, "p") Edge;
int N, M;
Edge[][] adj, rev;
real[] mem;

real dp(int n) {
    if (n == 0) return 0;
    if (mem[n] >= 0) return mem[n];

    real ret = 1;
    foreach (m; rev[n]) {
        real q = dp(m.to);
        ret *= q + (1 - q) * (1 - m.p);
    }

    return mem[n] = ret;
}

void main() {
    auto s = readln.split.map!(to!int);
    N = s[0];
    M = s[1];
    adj = new Edge[][](N);
    rev = new Edge[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        adj[s[0]] ~= Edge(s[1], s[2]*0.01L);
        rev[s[1]] ~= Edge(s[0], s[2]*0.01L);
    }

    mem = new real[](N);
    fill(mem, -1);

    writefln("%.9f", 1 - dp(N-1));
    //mem.writeln;
    //rev.each!writeln;
}
0