結果

問題 No.697 池の数はいくつか
ユーザー cympfhcympfh
提出日時 2018-06-13 15:34:49
言語 Ruby
(3.3.0)
結果
MLE  
実行時間 -
コード長 425 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 574,484 KB
最終ジャッジ日時 2024-05-04 05:53:19
合計ジャッジ時間 28,455 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
12,160 KB
testcase_01 AC 74 ms
12,160 KB
testcase_02 AC 75 ms
12,160 KB
testcase_03 AC 75 ms
12,288 KB
testcase_04 AC 76 ms
12,160 KB
testcase_05 AC 77 ms
12,160 KB
testcase_06 AC 76 ms
12,416 KB
testcase_07 AC 74 ms
12,160 KB
testcase_08 AC 77 ms
12,416 KB
testcase_09 AC 78 ms
12,160 KB
testcase_10 AC 80 ms
12,160 KB
testcase_11 AC 77 ms
12,288 KB
testcase_12 AC 75 ms
12,288 KB
testcase_13 AC 75 ms
12,160 KB
testcase_14 AC 74 ms
12,160 KB
testcase_15 AC 75 ms
12,160 KB
testcase_16 AC 76 ms
12,288 KB
testcase_17 AC 73 ms
12,160 KB
testcase_18 AC 72 ms
12,288 KB
testcase_19 AC 74 ms
12,416 KB
testcase_20 AC 76 ms
12,416 KB
testcase_21 AC 74 ms
12,160 KB
testcase_22 AC 75 ms
12,288 KB
testcase_23 AC 75 ms
12,160 KB
testcase_24 AC 3,239 ms
65,164 KB
testcase_25 AC 3,240 ms
65,392 KB
testcase_26 AC 3,213 ms
65,224 KB
testcase_27 AC 3,197 ms
65,332 KB
testcase_28 AC 3,231 ms
65,168 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h, w = gets.split.map(&:to_i)
memo = {}
h.times {|i|
  s = gets.split.map(&:to_i)
  w.times {|j|
    if s[j] == 1
      memo[[i, j]] = true
    end
  }
}
ans = 0
memo.keys.each do |i, j|
  next if memo[[i, j]] != true
  ans += 1
  s = [[i, j]]
  while s.size > 0
    i, j = s.pop
    next if memo[[i, j]] != true
    memo[[i, j]] = false
    s << [i+1, j]
    s << [i-1, j]
    s << [i, j+1]
    s << [i, j-1]
  end
end
p ans
0