結果

問題 No.298 話の伝達
ユーザー cielciel
提出日時 2015-11-09 21:22:47
言語 Crystal
(1.11.2)
結果
AC  
実行時間 586 ms / 5,000 ms
コード長 467 bytes
コンパイル時間 18,895 ms
コンパイル使用メモリ 262,900 KB
実行使用メモリ 5,296 KB
最終ジャッジ日時 2023-09-13 09:00:27
合計ジャッジ時間 22,242 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,456 KB
testcase_01 AC 3 ms
4,416 KB
testcase_02 AC 3 ms
4,492 KB
testcase_03 AC 2 ms
4,588 KB
testcase_04 AC 3 ms
4,468 KB
testcase_05 AC 255 ms
5,108 KB
testcase_06 AC 4 ms
4,864 KB
testcase_07 AC 3 ms
4,476 KB
testcase_08 AC 3 ms
4,500 KB
testcase_09 AC 4 ms
4,820 KB
testcase_10 AC 11 ms
4,792 KB
testcase_11 AC 305 ms
4,900 KB
testcase_12 AC 153 ms
4,920 KB
testcase_13 AC 352 ms
5,124 KB
testcase_14 AC 159 ms
5,212 KB
testcase_15 AC 2 ms
4,488 KB
testcase_16 AC 586 ms
5,228 KB
testcase_17 AC 10 ms
5,168 KB
testcase_18 AC 127 ms
5,296 KB
testcase_19 AC 3 ms
4,428 KB
testcase_20 AC 288 ms
5,188 KB
権限があれば一括ダウンロードができます

ソースコード

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