結果
| 問題 | No.679 不思議マーケット |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-30 23:46:56 |
| 言語 | Ruby (4.0.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 358 bytes |
| 記録 | |
| コンパイル時間 | 65 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,800 KB |
| 最終ジャッジ日時 | 2024-06-28 00:00:38 |
| 合計ジャッジ時間 | 2,520 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 RE * 15 |
コンパイルメッセージ
Main.rb:18: warning: assigned but unused variable - r Syntax OK
ソースコード
#!/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)