結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2020-02-09 14:34:34 |
言語 | Swift (6.0.3) |
結果 |
AC
|
実行時間 | 2,308 ms / 6,000 ms |
コード長 | 1,126 bytes |
コンパイル時間 | 1,519 ms |
コンパイル使用メモリ | 133,688 KB |
実行使用メモリ | 284,004 KB |
最終ジャッジ日時 | 2024-11-08 08:31:25 |
合計ジャッジ時間 | 17,476 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
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"} } } func main() { let (H, W) = readInt2() var A = readLines(H) let 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()! 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) } main()