結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
|
| 提出日時 | 2020-04-30 07:56:33 |
| 言語 | Swift (6.2.3) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,210 bytes |
| 記録 | |
| コンパイル時間 | 3,112 ms |
| コンパイル使用メモリ | 191,756 KB |
| 実行使用メモリ | 395,704 KB |
| 最終ジャッジ日時 | 2024-11-25 16:06:17 |
| 合計ジャッジ時間 | 74,090 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 23 TLE * 8 MLE * 1 |
ソースコード
import Foundation
func readInt2() -> (Int16, Int16) {
let l = readLine()!.split(separator: " ").map{Int16($0)!}
return (l[0], l[1])
}
func readLines(_ n: Int16) -> [[Bool]] {
return (0..<n).map{(Int16) -> [Bool] in
return readLine()!.split(separator: " ").map{$0 == "1"}
}
}
func bfs(_ i: Int16, _ j: Int16, _ grid: inout [[Bool]], _ H: Int16, _ W: Int16) -> Int{
var frontier = ArraySlice<(Int16, Int16)>()
frontier.append((i, j))
let dires: [(Int16, Int16)] = [(-1, 0),(0, 1),(1, 0),(0, -1)]
while let (h, w) = frontier.popFirst() {
grid[Int(h)][Int(w)] = false
for (y, x) in dires {
let sucY = h+y
let sucX = w+x
if sucY < 0 || sucY >= H || sucX < 0 || sucX >= W || !grid[Int(sucY)][Int(sucX)] {
continue
}
frontier.append((sucY, sucX))
}
}
return 1
}
func test() {
let (H, W): (Int16, Int16) = readInt2()
var A = readLines(H)
var ans = 0
for i in 0..<H {
for j in 0..<W {
if !A[Int(i)][Int(j)] {
continue
}
ans += bfs(i, j, &A, H, W)
}
}
print(ans)
}
test()