結果

問題 No.30 たこやき工場
ユーザー ayame_pyayame_py
提出日時 2015-10-13 04:42:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 491 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 11,416 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2023-08-23 05:16:48
合計ジャッジ時間 2,436 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,252 KB
testcase_01 AC 83 ms
15,128 KB
testcase_02 AC 82 ms
15,180 KB
testcase_03 AC 83 ms
15,264 KB
testcase_04 AC 81 ms
15,156 KB
testcase_05 AC 81 ms
15,240 KB
testcase_06 AC 82 ms
15,184 KB
testcase_07 AC 81 ms
15,268 KB
testcase_08 AC 83 ms
15,048 KB
testcase_09 AC 87 ms
15,636 KB
testcase_10 AC 109 ms
17,152 KB
testcase_11 AC 84 ms
15,332 KB
testcase_12 AC 82 ms
15,148 KB
testcase_13 AC 80 ms
15,308 KB
testcase_14 AC 84 ms
15,396 KB
testcase_15 AC 82 ms
15,584 KB
testcase_16 AC 84 ms
15,608 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
M=gets.to_i
$dp=Array.new(N){Array.new(N,-1)}
$e=Array.new(N){Array.new(M)}
$c=Array.new(N){Array.new(M)}
$en=Array.new(N,0)
M.times{
	s,q,r=gets.split.map(&:to_i)
	s-=1
	r-=1
	$e[r][$en[r]]=s
	$c[r][$en[r]]=q
	$en[r]+=1
}

def dfs(n)
	return 0 if $dp[n][0]>=0
	N.times{|i| $dp[n][i]=0}
	if($en[n]==0)
	 	$dp[n][n]=1
	 	return 0
	end
	$en[n].times{|i|
		s=$e[n][i]
		dfs(s)
		N.times{|j| $dp[n][j]+=$dp[s][j]*$c[n][i]}
	}
	return 0
end
dfs(N-1)
(N-1).times{|i| puts $dp[N-1][i]}
0