結果
問題 |
No.13 囲みたい!
|
ユーザー |
|
提出日時 | 2017-05-20 16:16:06 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 139 ms / 5,000 ms |
コード長 | 848 bytes |
コンパイル時間 | 95 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 13,824 KB |
最終ジャッジ日時 | 2024-09-19 00:27:54 |
合計ジャッジ時間 | 2,532 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
def f(board, width, height) visited = {} g = lambda{|h, w, n=board[h][w], cnt=0, from=nil| return if !h.between?(0, height-1) return if !w.between?(0, width-1) return if n != board[h][w] # p [n, cnt, [h,w]] return !from.nil? if visited[[h,w]] cnt += 1 visited[[h,w]] = true from != :l && g.(h, w-1, n, cnt, :r) || from != :r && g.(h, w+1, n, cnt, :l) || from != :u && g.(h-1, w, n, cnt, :d) || from != :d && g.(h+1, w, n, cnt, :u) } # visited.each{|l| puts l.join} height.times{|h| width.times{|w| if g.(h, w) # p [h,w] # visited.each{|l| puts l.join} return true end } } # visited.each{|l| puts l.join} false end W, H = gets.split.take(2).map(&:to_i) M = H.times.map{gets.split.take(W).map(&:to_i)} puts f(M, W, H) ? :possible : :impossible