結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
|
| 提出日時 | 2021-03-22 02:17:30 |
| 言語 | Ruby (3.4.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 930 bytes |
| コンパイル時間 | 209 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 734,208 KB |
| 最終ジャッジ日時 | 2024-11-25 16:58:47 |
| 合計ジャッジ時間 | 54,063 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | MLE * 3 |
| other | AC * 8 WA * 16 TLE * 5 MLE * 3 |
コンパイルメッセージ
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.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