結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-06-13 15:41:09 |
言語 | Ruby (3.4.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 514 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 820,992 KB |
最終ジャッジ日時 | 2024-11-25 13:38:18 |
合計ジャッジ時間 | 53,349 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | MLE * 3 |
other | AC * 17 WA * 9 TLE * 5 MLE * 1 |
コンパイルメッセージ
Syntax OK
ソースコード
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