結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2020-08-26 15:19:17 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 913 bytes |
コンパイル時間 | 362 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 82,304 KB |
最終ジャッジ日時 | 2024-11-25 16:28:02 |
合計ジャッジ時間 | 37,882 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 TLE * 2 |
ソースコード
# import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) # from collections import defaultdict from collections import deque def getlist(): return list(map(int, input().split())) def BFS(H, W, L, start): h, w = start Q = deque(); Q.append([h, w]) while Q: y, x = Q.popleft() if L[y - 1][x] == 1: L[y - 1][x] = 2 Q.append([y - 1, x]) if L[y + 1][x] == 1: L[y + 1][x] = 2 Q.append([y + 1, x]) if L[y][x - 1] == 1: L[y][x - 1] = 2 Q.append([y, x - 1]) if L[y][x + 1] == 1: L[y][x + 1] = 2 Q.append([y, x + 1]) #処理内容 def main(): H, W = getlist() L = [] L.append([0] * (W + 2)) for i in range(H): l = getlist() L.append([0] + l + [0]) L.append([0] * (W + 2)) cnt = 0 for i in range(1, H + 1): for j in range(1, W + 1): if L[i][j] == 1: cnt += 1 BFS(H + 2, W + 2, L, [i, j]) print(cnt) if __name__ == '__main__': main()