結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2020-02-09 14:23:34 |
言語 | Swift (6.0.3) |
結果 |
AC
|
実行時間 | 2,353 ms / 6,000 ms |
コード長 | 1,074 bytes |
コンパイル時間 | 12,063 ms |
コンパイル使用メモリ | 187,280 KB |
実行使用メモリ | 290,140 KB |
最終ジャッジ日時 | 2024-11-08 08:30:11 |
合計ジャッジ時間 | 28,378 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
import Foundation func readInt2() -> (Int, Int) { let l = readLine()!.split(separator: " ").map{Int($0)!} return (l[0], l[1]) } func readLines(_ n: Int) -> [[Bool]] { return (0..<n).map{(Int) -> [Bool] in return readLine()!.split(separator: " ").map{$0 == "1"} } } let (H, W) = readInt2() var A = readLines(H) var dirc = [(-1, 0),(0, 1),(1, 0),(0, -1)] var ans = 0 for i in 0..<H { for j in 0..<W { if !A[i][j] { continue } ans += 1 var frontier: [(Int, Int)] = [] frontier.append((i, j)) while !frontier.isEmpty { let (h, w) = frontier.popLast()! if !A[h][w]{ continue } A[h][w] = false for (y, x) in dirc { let sucY = h+y let sucX = w+x if sucY < 0 || sucY >= H || sucX < 0 || sucX >= W || !A[sucY][sucX] { continue } frontier.append((sucY, sucX)) } } } } print(ans)