結果

問題 No.697 池の数はいくつか
ユーザー masashi0217masashi0217
提出日時 2021-03-22 02:24:37
言語 Ruby
(3.3.0)
結果
MLE  
実行時間 -
コード長 1,038 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 11,488 KB
実行使用メモリ 707,712 KB
最終ジャッジ日時 2023-08-17 00:00:17
合計ジャッジ時間 21,361 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,332 KB
testcase_01 AC 83 ms
15,240 KB
testcase_02 AC 86 ms
15,232 KB
testcase_03 AC 83 ms
15,224 KB
testcase_04 AC 82 ms
15,240 KB
testcase_05 AC 83 ms
15,164 KB
testcase_06 AC 82 ms
15,252 KB
testcase_07 AC 87 ms
15,148 KB
testcase_08 AC 83 ms
15,116 KB
testcase_09 AC 81 ms
15,124 KB
testcase_10 AC 84 ms
15,336 KB
testcase_11 AC 82 ms
15,096 KB
testcase_12 AC 81 ms
15,320 KB
testcase_13 AC 81 ms
15,172 KB
testcase_14 AC 83 ms
15,104 KB
testcase_15 AC 88 ms
15,236 KB
testcase_16 AC 81 ms
15,340 KB
testcase_17 AC 82 ms
15,248 KB
testcase_18 AC 84 ms
15,276 KB
testcase_19 AC 84 ms
15,060 KB
testcase_20 AC 81 ms
15,076 KB
testcase_21 AC 81 ms
15,224 KB
testcase_22 AC 83 ms
15,256 KB
testcase_23 AC 82 ms
15,052 KB
testcase_24 AC 1,871 ms
72,640 KB
testcase_25 AC 1,858 ms
71,324 KB
testcase_26 AC 1,868 ms
72,448 KB
testcase_27 AC 1,872 ms
72,684 KB
testcase_28 AC 1,856 ms
72,528 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
    tmp = [[i,j]]
    until tmp == []
        i,j = tmp.pop
    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
            tmp << [yy,xx]
            count += 1
        end
    end
    #p spot
end
# p spot_count
# p count
puts spot_count - count
0