結果
| 問題 | 
                            No.13 囲みたい!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-09-21 16:25:11 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,106 bytes | 
| コンパイル時間 | 240 ms | 
| コンパイル使用メモリ | 7,424 KB | 
| 実行使用メモリ | 13,568 KB | 
| 最終ジャッジ日時 | 2024-11-17 10:26:02 | 
| 合計ジャッジ時間 | 3,840 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | WA * 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 'possipble'
else
  puts 'impossible'
end