結果
問題 |
No.298 話の伝達
|
ユーザー |
|
提出日時 | 2017-04-02 19:01:02 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 928 bytes |
コンパイル時間 | 2,372 ms |
コンパイル使用メモリ | 163,532 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 18:35:26 |
合計ジャッジ時間 | 3,161 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 11 |
ソースコード
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; }