結果

問題 No.697 池の数はいくつか
ユーザー cympfhcympfh
提出日時 2018-06-13 15:41:09
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 514 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 817,536 KB
最終ジャッジ日時 2024-05-04 05:54:22
合計ジャッジ時間 15,959 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
12,160 KB
testcase_01 WA -
testcase_02 AC 84 ms
12,288 KB
testcase_03 AC 80 ms
12,288 KB
testcase_04 WA -
testcase_05 AC 79 ms
12,160 KB
testcase_06 AC 78 ms
12,160 KB
testcase_07 AC 80 ms
12,160 KB
testcase_08 AC 78 ms
12,160 KB
testcase_09 AC 78 ms
12,288 KB
testcase_10 WA -
testcase_11 AC 81 ms
12,160 KB
testcase_12 AC 80 ms
12,160 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 80 ms
12,160 KB
testcase_16 AC 78 ms
12,160 KB
testcase_17 AC 77 ms
12,160 KB
testcase_18 AC 76 ms
12,160 KB
testcase_19 AC 77 ms
12,160 KB
testcase_20 AC 76 ms
12,160 KB
testcase_21 AC 83 ms
12,160 KB
testcase_22 AC 79 ms
12,288 KB
testcase_23 AC 78 ms
12,160 KB
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.split.map(&:to_i)
memo = [nil] * h
h.times{|i| memo[i] = [false] * w}
ls = []
h.times {|i|
  s = gets.split.map(&:to_i)
  w.times {|j|
    if s[j] == 1
      memo[i][j] = true
      ls << [i, j]
    end
  }
}
ans = 0
ls.each do |i, j|
  next unless memo[i][j]
  ans += 1
  s = [[i, j]]
  while s.size > 0
    i, j = s.pop
    next unless memo[i][j]
    memo[i][j] = false
    s << [i+1, j] if i < h-1
    # s << [i-1, j] if i > 0
    s << [i, j+1] if j < w-1
    s << [i, j-1] if j > 0
  end
end
p ans
0