結果
問題 | No.157 2つの空洞 |
ユーザー | takuk |
提出日時 | 2015-03-02 11:34:47 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 1,508 bytes |
コンパイル時間 | 71 ms |
コンパイル使用メモリ | 11,468 KB |
実行使用メモリ | 15,344 KB |
最終ジャッジ日時 | 2023-09-06 06:28:38 |
合計ジャッジ時間 | 2,585 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 80 ms
15,240 KB |
testcase_01 | AC | 77 ms
15,264 KB |
testcase_02 | AC | 74 ms
15,068 KB |
testcase_03 | AC | 79 ms
15,336 KB |
testcase_04 | AC | 76 ms
15,044 KB |
testcase_05 | AC | 79 ms
15,236 KB |
testcase_06 | AC | 82 ms
15,288 KB |
testcase_07 | AC | 77 ms
15,132 KB |
testcase_08 | AC | 78 ms
15,040 KB |
testcase_09 | AC | 80 ms
15,288 KB |
testcase_10 | AC | 79 ms
15,140 KB |
testcase_11 | AC | 76 ms
15,344 KB |
testcase_12 | AC | 78 ms
15,128 KB |
testcase_13 | AC | 76 ms
15,128 KB |
testcase_14 | AC | 76 ms
15,136 KB |
testcase_15 | AC | 77 ms
15,240 KB |
testcase_16 | AC | 78 ms
15,260 KB |
testcase_17 | AC | 79 ms
15,236 KB |
testcase_18 | AC | 82 ms
15,124 KB |
testcase_19 | AC | 82 ms
15,036 KB |
コンパイルメッセージ
Syntax OK
ソースコード
def pp(c) c.each do |l| puts l end puts end $dx = [0,1,0,-1] $dy = [1,0,-1,0] $m = Array.new $mm = Array.new w, h = gets.split.map(&:to_i) c = h.times.map{gets.chomp} bl = false c.each_with_index do |line,i| line.each_char.with_index do |cc,j| next unless cc == "." q = [[i,j]] while q.size > 0 sy, sx = q.shift c[sy][sx] = "a" $m.push([sy,sx]) for i in 0..3 cy = sy + $dy[i] cx = sx + $dx[i] if c[cy][cx] == "." && cy.between?(1,h-2) && cx.between?(1,w-2) && !q.include?([cy,cx]) q.push([cy,cx]) end end end bl = true break end break if bl end bl = false c.each_with_index do |line,i| line.each_char.with_index do |cc,j| next unless cc == "." q = [[i,j]] while q.size > 0 sy, sx = q.shift c[sy][sx] = "b" $mm.push([sy,sx]) for i in 0..3 cy = sy + $dy[i] cx = sx + $dx[i] if c[cy][cx]=="." && cy.between?(1,h-2) && cx.between?(1,w-2) && !q.include?([cy,cx]) q.push([cy,cx]) end end end bl = true break end break if bl end ret = Float::INFINITY $m.each do |p| $mm.each do |pp| t = (p[0] - pp[0]).abs + (p[1] - pp[1]).abs - 1 ret = t if t < ret end end p ret