結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
小指が強い人
|
| 提出日時 | 2015-11-23 16:48:05 |
| 言語 | Ruby (3.4.1) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
コンパイルメッセージ
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
小指が強い人