結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-06-15 22:13:36 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 499 bytes | 
| コンパイル時間 | 120 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 169,984 KB | 
| 最終ジャッジ日時 | 2024-11-25 13:39:50 | 
| 合計ジャッジ時間 | 45,513 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 RE * 2 TLE * 4 | 
コンパイルメッセージ
Syntax OK
ソースコード
# https://yukicoder.me/problems/no/697
H, W = gets.split.map &:to_i
board = $<.map{|s|s.split.map &:to_i}
used = H.times.map{[false] * W}
DIRS = [[0, 1], [0, -1], [1, 0], [-1, 0]]
f = ->y, x{
  return if !y.between?(0, H-1)
  return if !x.between?(0, W-1)
  return if board[y][x] == 0
  return if used[y][x]
  used[y][x] = true
  DIRS.each{|dy, dx|
    f[y+dy, x+dx]
  }
}
ans = 0
H.times{|i|
  W.times{|j|
    next if board[i][j] == 0
    next if used[i][j]
    ans += 1
    f[i, j]
  }
}
p ans