結果

問題 No.697 池の数はいくつか
ユーザー masashi0217masashi0217
提出日時 2021-03-22 02:17:30
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 930 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 730,620 KB
最終ジャッジ日時 2023-08-16 23:59:06
合計ジャッジ時間 20,066 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
15,336 KB
testcase_01 WA -
testcase_02 AC 88 ms
15,264 KB
testcase_03 AC 86 ms
15,248 KB
testcase_04 WA -
testcase_05 AC 86 ms
15,076 KB
testcase_06 AC 86 ms
15,160 KB
testcase_07 WA -
testcase_08 AC 87 ms
15,264 KB
testcase_09 AC 84 ms
15,336 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 85 ms
15,344 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 84 ms
15,248 KB
testcase_16 AC 83 ms
15,228 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 77 ms
15,136 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
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.shift
    # 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