結果
問題 | No.157 2つの空洞 |
ユーザー | 小指が強い人 |
提出日時 | 2015-11-23 16:48:05 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 1,395 bytes |
コンパイル時間 | 83 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-09-13 17:17:09 |
合計ジャッジ時間 | 2,699 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
12,160 KB |
testcase_01 | AC | 95 ms
12,288 KB |
testcase_02 | AC | 87 ms
12,160 KB |
testcase_03 | AC | 89 ms
12,288 KB |
testcase_04 | AC | 89 ms
12,160 KB |
testcase_05 | AC | 89 ms
12,288 KB |
testcase_06 | AC | 91 ms
12,160 KB |
testcase_07 | AC | 89 ms
12,160 KB |
testcase_08 | AC | 89 ms
12,160 KB |
testcase_09 | AC | 89 ms
12,160 KB |
testcase_10 | AC | 89 ms
12,032 KB |
testcase_11 | AC | 89 ms
12,160 KB |
testcase_12 | AC | 87 ms
12,160 KB |
testcase_13 | AC | 89 ms
12,160 KB |
testcase_14 | AC | 90 ms
12,288 KB |
testcase_15 | AC | 91 ms
12,032 KB |
testcase_16 | AC | 90 ms
12,160 KB |
testcase_17 | AC | 91 ms
12,288 KB |
testcase_18 | AC | 89 ms
12,160 KB |
testcase_19 | AC | 88 ms
12,288 KB |
コンパイルメッセージ
Main.rb:1: warning: possibly useless use of a variable in void context Main.rb:2: warning: possibly useless use of a variable in void context Main.rb:3: warning: possibly useless use of a variable in void context Main.rb:4: warning: possibly useless use of a variable in void context Main.rb:5: warning: possibly useless use of a variable in void context Main.rb:42: warning: assigned but unused variable - d Syntax OK
ソースコード
$w $h $a $b $c $dx = [1, 0, -1, 0] $dy = [0, 1, 0, -1] $min = 10 ** 10 def checkRange(x, y) return x >= 0 && x < $w && y >= 0 && y < $h end def paint(cx, cy, v) $b[cy][cx] = true if $c[cy][cx] == "#" return end $a[cy][cx] = v 4.times do |i| tx = cx + $dx[i] ty = cy + $dy[i] next if !checkRange(tx, ty) || $b[ty][tx] paint(tx, ty, v) end end $w, $h = gets.split.map(&:to_i) $a = Array.new($h).map{ Array.new($w, 0) } $b = Array.new($h).map{ Array.new($w, false) } $c = Array.new($h) $h.times do |i| $c[i] = gets.strip end v = 1 $h.times do |i| $w.times do |j| if $c[i][j] == "." && $a[i][j] == 0 paint(j, i, v) v += 1 end end end coord = Struct.new(:x, :y) d = Array.new($h).map{ Array.new($w, false) } ah = Array.new bh = Array.new $h.times do |i| $w.times do |j| if $a[i][j] != 0 next end 4.times do |k| tx = j + $dx[k] ty = i + $dy[k] next if !checkRange(tx, ty) if $a[ty][tx] == 1 ah.push(coord.new(j, i)) elsif $a[ty][tx] == 2 bh.push(coord.new(j, i)) end end end end min = 10 ** 10 ah.each do |a| bh.each do |b| v = (a.x - b.x).abs + (a.y - b.y).abs + 1 min = v if v < min end end puts min