結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-03-22 02:46:36 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 947 bytes | 
| コンパイル時間 | 136 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 740,992 KB | 
| 最終ジャッジ日時 | 2024-11-25 17:00:43 | 
| 合計ジャッジ時間 | 53,788 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 MLE * 2 | 
| other | AC * 23 TLE * 5 MLE * 4 | 
コンパイルメッセージ
Main.rb:14: warning: assigned but unused variable - island Syntax OK
ソースコード
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
    arr[i][j] = 0
    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
        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