結果

問題 No.13 囲みたい!
ユーザー gigurururugigurururu
提出日時 2014-11-28 13:35:53
言語 Ruby
(3.3.0)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 494 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-04-21 12:15:12
合計ジャッジ時間 2,983 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
12,160 KB
testcase_01 AC 73 ms
12,160 KB
testcase_02 AC 73 ms
12,416 KB
testcase_03 AC 94 ms
12,928 KB
testcase_04 AC 78 ms
12,416 KB
testcase_05 AC 112 ms
13,952 KB
testcase_06 AC 79 ms
12,544 KB
testcase_07 AC 115 ms
13,312 KB
testcase_08 AC 120 ms
13,568 KB
testcase_09 AC 123 ms
13,440 KB
testcase_10 AC 83 ms
12,672 KB
testcase_11 AC 110 ms
13,056 KB
testcase_12 AC 82 ms
12,416 KB
testcase_13 AC 93 ms
12,416 KB
testcase_14 AC 96 ms
12,544 KB
testcase_15 AC 77 ms
12,288 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)
  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"
0