結果
問題 | No.13 囲みたい! |
ユーザー |
|
提出日時 | 2014-11-27 22:09:03 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 3,584 ms / 5,000 ms |
コード長 | 541 bytes |
コンパイル時間 | 207 ms |
コンパイル使用メモリ | 8,064 KB |
実行使用メモリ | 182,528 KB |
最終ジャッジ日時 | 2025-01-03 09:19:32 |
合計ジャッジ時間 | 8,976 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) return false if $checked[[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 $checked[[tx,ty]]=true return true if gone.index([tx,ty]) 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"