結果

問題 No.697 池の数はいくつか
ユーザー masashi0217
提出日時 2021-03-22 02:15:52
言語 Ruby
(3.4.1)
結果
MLE  
実行時間 -
コード長 928 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 732,928 KB
最終ジャッジ日時 2024-11-25 16:59:48
合計ジャッジ時間 54,070 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 3
other AC * 24 TLE * 5 MLE * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h, w = gets.chomp.split(" ").map(&:to_i)
spot = []
arr = []
spot_count = 0
h.times do |i|
    a = gets.chomp.split(" ").map(&:to_i)
    arr << a
    a.each_with_index do |item,j|
        next if item == 0
        spot << [i,j]
        spot_count += 1
    end
end
island = Array.new(h).map{Array.new(w,false)}
count = 0
direction = [[0,-1],[0,1],[1,0],[-1,0]]
count = 0
#p spot
until spot == []
    i,j = spot.pop
    # puts "---------"
    # print "i" + "#{i}" + " " + "J" + "#{j}" + "\n"
    #p island
    island[i][j] = true
    direction.each do |x,y|
        yy = i + y
        xx = j + x
        next if (xx < 0 || xx > w-1) || (yy < 0 || yy > h-1)
        #print "xx"+"#{yy}" + " " + "yy"+"#{xx}" + "\n"
        next if arr[yy][xx] == 0
        next if island[yy][xx] == true
        island[yy][xx] = true
        spot << [yy,xx]
        count += 1
    end
    # p spot
end
# p spot_count
# p count
puts spot_count - count
0