結果
問題 | No.13 囲みたい! |
ユーザー |
|
提出日時 | 2017-05-20 15:51:32 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 102 ms / 5,000 ms |
コード長 | 936 bytes |
コンパイル時間 | 241 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 13,184 KB |
最終ジャッジ日時 | 2024-09-19 00:27:45 |
合計ジャッジ時間 | 2,903 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
def f(board, width, height) visited = height.times.map{[0]*width} g = lambda{|h, w, n, cnt=0, from=nil| return if !h.between?(0, height-1) return if !w.between?(0, width-1) return if n != board[h][w] if visited[h][w] > 0 # p [n, cnt, [h,w]] return cnt + visited[h][w] > 4 end cnt += 1 visited[h][w] = cnt 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| next if visited[h][w] > 0 if g.(h, w, board[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