結果

問題 No.13 囲みたい!
ユーザー gigurururugigurururu
提出日時 2014-11-27 22:16:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 3,568 ms / 5,000 ms
コード長 547 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 188,164 KB
最終ジャッジ日時 2023-09-01 22:21:45
合計ジャッジ時間 8,715 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,096 KB
testcase_01 AC 82 ms
15,236 KB
testcase_02 AC 82 ms
15,272 KB
testcase_03 AC 3,568 ms
188,164 KB
testcase_04 AC 92 ms
15,544 KB
testcase_05 AC 2,578 ms
138,092 KB
testcase_06 AC 133 ms
18,856 KB
testcase_07 AC 175 ms
18,184 KB
testcase_08 AC 136 ms
16,608 KB
testcase_09 AC 133 ms
16,464 KB
testcase_10 AC 89 ms
15,356 KB
testcase_11 AC 121 ms
16,092 KB
testcase_12 AC 85 ms
15,192 KB
testcase_13 AC 98 ms
15,532 KB
testcase_14 AC 98 ms
15,632 KB
testcase_15 AC 82 ms
15,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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"
0