結果

問題 No.13 囲みたい!
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2016-09-21 16:26:40
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 1,112 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 11,468 KB
実行使用メモリ 15,936 KB
最終ジャッジ日時 2023-08-10 23:39:10
合計ジャッジ時間 2,336 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 76 ms
15,124 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 82 ms
15,936 KB
testcase_06 WA -
testcase_07 AC 81 ms
15,408 KB
testcase_08 AC 85 ms
15,536 KB
testcase_09 WA -
testcase_10 AC 76 ms
15,032 KB
testcase_11 AC 85 ms
15,444 KB
testcase_12 AC 76 ms
15,240 KB
testcase_13 AC 78 ms
15,324 KB
testcase_14 AC 77 ms
15,248 KB
testcase_15 AC 74 ms
15,044 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

$w, $h, = gets.split.map(&:to_i)
$list = $h.times.map { gets.split.map(&:to_i) }
$check_list = Array.new($h) {Array.new($w, false)}

def check_loop(x, y)
  if $check_list[y][x]
    return false
  end
  check_point(x, y)
end

def check_point(x, y, pre = nil)
  if $check_list[y][x]
    return true
  end
  $check_list[y][x] = true
  if pre != :r && x > 0 && $list[y][x] == $list[y][x - 1]
    if check_point(x - 1, y, :l)
      return true
    end
  end
  if pre != :d && y > 0 && $list[y][x] == $list[y - 1][x]
    if check_point(x, y - 1, :u)
      return true
    end
  end
  if pre != :l && x < $w - 1 && $list[y][x] == $list[y][x + 1]
    if check_point(x + 1, y, :r)
      return true
    end
  end
  if pre != :u && y < $h - 1 && $list[y][x] == $list[y + 1][x]
    if check_point(x, y + 1, :d)
      return true
    end
  end
  return false
end

looped = false
$h.times do |y|
  $w.times do |x|
    if check_loop(x, y)
      looped = true
      break
    end
    if looped
      break
    end
  end
end

# require 'pp'
# pp $list
# pp $check_list

if looped
  puts 'possipble'
else
  puts 'impossible'
end
0