結果

問題 No.679 不思議マーケット
ユーザー cielciel
提出日時 2018-04-30 23:46:56
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 358 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,272 KB
実行使用メモリ 15,608 KB
最終ジャッジ日時 2023-09-10 08:33:40
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 80 ms
15,032 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 83 ms
15,608 KB
testcase_16 RE -
testcase_17 AC 81 ms
15,132 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:18: warning: assigned but unused variable - r
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def cycle(c,m,f,h)
	return f[c] if !f[c].nil?
	f[c]=h[c].all?{|e|
		if m.has_key?(e)
			false
		else
			m[e]=1
			f=cycle(e,m,f,h)
			m.delete e
			f
		end
	}
end
n,m=gets.split.map &:to_i
h=Hash.new{|h,k|h[k]=[]}
m.times{
g,r=gets.split.map &:to_i
h[g]=gets.split.map(&:to_i)
}
f=[nil]*-~n
(1..n).map{|i|cycle(i,{i=>1},f,h)}
p f.count(true)
0