結果

問題 No.13 囲みたい!
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2016-09-21 16:27:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 1,111 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 11,324 KB
実行使用メモリ 16,024 KB
最終ジャッジ日時 2023-08-10 23:39:19
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,168 KB
testcase_01 AC 81 ms
15,168 KB
testcase_02 AC 80 ms
15,160 KB
testcase_03 AC 85 ms
16,020 KB
testcase_04 AC 83 ms
15,560 KB
testcase_05 AC 86 ms
16,024 KB
testcase_06 AC 85 ms
15,680 KB
testcase_07 AC 89 ms
15,296 KB
testcase_08 AC 89 ms
15,580 KB
testcase_09 AC 90 ms
15,484 KB
testcase_10 AC 82 ms
15,028 KB
testcase_11 AC 89 ms
15,508 KB
testcase_12 AC 81 ms
15,312 KB
testcase_13 AC 83 ms
15,412 KB
testcase_14 AC 84 ms
15,432 KB
testcase_15 AC 80 ms
15,120 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 'possible'
else
  puts 'impossible'
end
0