結果

問題 No.298 話の伝達
ユーザー ciel
提出日時 2015-11-09 21:22:47
言語 Crystal
(1.14.0)
結果
AC  
実行時間 525 ms / 5,000 ms
コード長 467 bytes
コンパイル時間 12,110 ms
コンパイル使用メモリ 300,012 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 18:51:59
合計ジャッジ時間 14,991 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env crystal
n,m=gets.not_nil!.split.map(&.to_i)
G={} of Int32 => Array(Tuple(Int32,Float64))
m.times{
	a,b,c=gets.not_nil!.split.map(&.to_i)
	G[b]||=[] of Tuple(Int32,Float64)
	G[b]<<{a,c/100.0}
}
if n==1
	p 0
	exit
end
r=0
(1<<(n-2)).times{|i|
	a=[0.0]+[1.0]*(n-1)
	n.times{|j|
		G[j].each{|e|a[j]*=1-e[1] if e[0]==0||e[0]==n-1||(i&(1<<e[0]-1))!=0} if G.has_key?(j)
	}
	r0=1
	n.times{|j|
		r0*=j==0||j==n-1||(i&(1<<j-1))!=0 ? 1-a[j] : a[j]
	}
	r+=r0
}
p r
0