結果

問題 No.157 2つの空洞
ユーザー takuktakuk
提出日時 2015-03-02 10:58:59
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,209 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 11,284 KB
実行使用メモリ 87,268 KB
最終ジャッジ日時 2023-09-06 06:23:50
合計ジャッジ時間 5,877 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
19,676 KB
testcase_01 AC 80 ms
15,280 KB
testcase_02 AC 79 ms
15,248 KB
testcase_03 AC 80 ms
15,140 KB
testcase_04 AC 82 ms
15,052 KB
testcase_05 AC 82 ms
15,180 KB
testcase_06 WA -
testcase_07 AC 80 ms
15,056 KB
testcase_08 AC 79 ms
15,056 KB
testcase_09 AC 77 ms
15,040 KB
testcase_10 AC 78 ms
15,144 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 215 ms
15,656 KB
testcase_15 AC 115 ms
15,376 KB
testcase_16 AC 83 ms
15,044 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def pp(c)
    c.each do |l|
        puts l
    end
end
$dx = [0,1,0,-1]
$dy = [1,0,-1,0]
$m = Array.new
def fill(c,i,j,ch,h,w)
    q = [[i,j]]
    while q.size > 0
        sy, sx = q.shift
        c[sy][sx] = ch
        $m.push([sy,sx])
        for i in 0..3
            cy = sy + $dy[i]
            cx = sx + $dx[i]
            if cy.between?(0,h-1) && cx.between?(0,w-1) && c[cy][cx]=="."
                q.push([cy,cx])
            end
        end
    end
end

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 == "."
        fill(c,i,j,"0",h,w)
        bl = true
        break
    end
    break if bl
end
bl = false
ret = 0
while $m.size > 0
    sy, sx = $m.shift
    for i in 0..3
        cy = sy + $dy[i]
        cx = sx + $dx[i]
        if c[cy][cx] == "."
            ret = c[sy][sx].to_i
            bl = true
            break
        elsif cy.between?(1,h-2) && cx.between?(1,w-2) && c[cy][cx]=="\#"
            if !$m.include?([cy,cx])
                $m.push([cy,cx]) 
                c[cy][cx] = (c[sy][sx].to_i + 1).to_s
            end
        end
    end
    break if bl
end
p ret
0