結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2014-11-27 22:16:04 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3,707 ms / 5,000 ms | 
| コード長 | 547 bytes | 
| コンパイル時間 | 212 ms | 
| コンパイル使用メモリ | 8,192 KB | 
| 実行使用メモリ | 188,800 KB | 
| 最終ジャッジ日時 | 2025-01-03 09:20:27 | 
| 合計ジャッジ時間 | 9,421 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
コンパイルメッセージ
Syntax OK
ソースコード
def g;gets.split.map(&:to_i);end
w,h=g
$m=(1..h).map{g+[0]}+[0]*w
$checked={}
def dfs(x,y)
  r=[[0,-1],[1,0],[-1,0],[0,1]]
  c=$m[y][x]
  stack=[[[],-1,x,y]]
  while stack[0]
    gone,dir,tx,ty=stack.pop
    if $m[ty][tx]==c
      return true if gone.index([tx,ty])
      return false if $checked[[tx,ty]]
      $checked[[tx,ty]]=true
      4.times{|i|i!=dir&&stack.push([gone+[[tx,ty]],3-i,tx+r[i][0],ty+r[i][1]])}
    end
  end
  return false
end
puts (0...h).any?{|y|(0...w).any?{|x|dfs(x,y)}}?"possible":"impossible"
            
            
            
        