結果

問題 No.697 池の数はいくつか
ユーザー masashi0217masashi0217
提出日時 2021-03-22 02:15:52
言語 Ruby
(3.3.0)
結果
MLE  
実行時間 -
コード長 928 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 11,368 KB
実行使用メモリ 707,684 KB
最終ジャッジ日時 2023-08-16 23:59:35
合計ジャッジ時間 21,354 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,368 KB
testcase_01 AC 84 ms
15,148 KB
testcase_02 AC 85 ms
15,036 KB
testcase_03 AC 85 ms
15,300 KB
testcase_04 AC 84 ms
15,336 KB
testcase_05 AC 84 ms
15,276 KB
testcase_06 AC 85 ms
15,156 KB
testcase_07 AC 85 ms
15,040 KB
testcase_08 AC 86 ms
15,056 KB
testcase_09 AC 84 ms
15,332 KB
testcase_10 AC 83 ms
15,164 KB
testcase_11 AC 84 ms
15,348 KB
testcase_12 AC 82 ms
15,096 KB
testcase_13 AC 83 ms
15,156 KB
testcase_14 AC 82 ms
15,152 KB
testcase_15 AC 81 ms
15,352 KB
testcase_16 AC 85 ms
15,320 KB
testcase_17 AC 82 ms
15,120 KB
testcase_18 AC 83 ms
15,360 KB
testcase_19 AC 81 ms
15,264 KB
testcase_20 AC 82 ms
15,084 KB
testcase_21 AC 85 ms
15,144 KB
testcase_22 AC 83 ms
15,096 KB
testcase_23 AC 85 ms
15,312 KB
testcase_24 AC 1,612 ms
72,776 KB
testcase_25 AC 1,609 ms
71,456 KB
testcase_26 AC 1,609 ms
72,820 KB
testcase_27 AC 1,604 ms
72,584 KB
testcase_28 AC 1,604 ms
72,564 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
    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