結果
問題 | No.13 囲みたい! |
ユーザー |
|
提出日時 | 2016-09-21 16:27:32 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 101 ms / 5,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-11-17 10:27:11 |
合計ジャッジ時間 | 2,183 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
$w, $h, = gets.split.map(&:to_i) $list = $h.times.map { gets.split.map(&:to_i) } $check_list = Array.new($h) {Array.new($w, false)} def check_loop(x, y) if $check_list[y][x] return false end check_point(x, y) end def check_point(x, y, pre = nil) if $check_list[y][x] return true end $check_list[y][x] = true if pre != :r && x > 0 && $list[y][x] == $list[y][x - 1] if check_point(x - 1, y, :l) return true end end if pre != :d && y > 0 && $list[y][x] == $list[y - 1][x] if check_point(x, y - 1, :u) return true end end if pre != :l && x < $w - 1 && $list[y][x] == $list[y][x + 1] if check_point(x + 1, y, :r) return true end end if pre != :u && y < $h - 1 && $list[y][x] == $list[y + 1][x] if check_point(x, y + 1, :d) return true end end return false end looped = false $h.times do |y| $w.times do |x| if check_loop(x, y) looped = true break end if looped break end end end # require 'pp' # pp $list # pp $check_list if looped puts 'possible' else puts 'impossible' end