結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2020-08-26 15:16:40 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,123 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 305,408 KB |
最終ジャッジ日時 | 2024-11-25 16:24:32 |
合計ジャッジ時間 | 43,100 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 TLE * 2 MLE * 1 |
ソースコード
# 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, visit, start): h, w = start Q = deque(); Q.append([h, w]) while Q: y, x = Q.popleft() if L[y - 1][x] == 1 and visit[y - 1][x] == 0: visit[y - 1][x] = 1 Q.append([y - 1, x]) if L[y + 1][x] == 1 and visit[y + 1][x] == 0: visit[y + 1][x] = 1 Q.append([y + 1, x]) if L[y][x - 1] == 1 and visit[y][x - 1] == 0: visit[y][x - 1] = 1 Q.append([y, x - 1]) if L[y][x + 1] == 1 and visit[y][x + 1] == 0: visit[y][x + 1] = 1 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)) visit = [[0] * (W + 2) for i in range(H + 2)] # print(L) cnt = 0 for i in range(1, H + 1): for j in range(1, W + 1): if visit[i][j] == 0 and L[i][j] == 1: cnt += 1 BFS(H + 2, W + 2, L, visit, [i, j]) print(cnt) if __name__ == '__main__': main()