結果

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

ソースコード

diff #

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}
}
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