結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2014-11-28 13:35:53 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 128 ms / 5,000 ms | 
| コード長 | 494 bytes | 
| コンパイル時間 | 141 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 13,696 KB | 
| 最終ジャッジ日時 | 2024-10-13 10:39:30 | 
| 合計ジャッジ時間 | 2,473 ms | 
| ジャッジサーバーID (参考情報) | judge4 / 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)
  return if $checked[[x,y]]
  r=[[0,-1],[1,0],[-1,0],[0,1]]
  c=$m[y][x]
  stack=[[-1,x,y]]
  while stack[0]
    dir,tx,ty=stack.pop
    if $m[ty][tx]==c
      return true if $checked[[tx,ty]]
      $checked[[tx,ty]]=true
      4.times{|i|i!=dir&&stack.push([3-i,tx+r[i][0],ty+r[i][1]])}
    end
  end
end
puts (0...h).any?{|y|(0...w).any?{|x|dfs(x,y)}}?"possible":"impossible"
            
            
            
        