from collections import deque
dx=[-1,1,0,0]
dy=[0,0,-1,1]
complex=[]
cnt=[]
n=int(input())
for i in range(n):
complex.append(list(str(input())))
def bfs(x1,y1):
cnt=0
q=deque([(x1,y1)])
complex[x1][y1]=0
while q:
x,y=q.pop()
cnt+=1
for i in range(4):
xx=x+dx[i]
yy=y+dy[i]
if 0<=xx<n and 0<=yy<n and complex[xx][yy]=='1':
complex[xx][yy]=0
q.append((xx,yy))
return cnt
for x in range(n):
for y in range(n):
if complex[x][y]=='1':
cnt.append(bfs(x,y))
print(len(cnt))
cnt.sort()
for _ in cnt:
print(_)
'알고리즘 > 백준' 카테고리의 다른 글
백준-2750번(수 정렬하기)-python3 (0) | 2023.11.26 |
---|---|
백준-2675번(문자열 반복)-python3 (1) | 2023.11.24 |
백준-2644번(촌수계산)-python3 (0) | 2023.11.24 |
백준-2609번(최대공약수와 최소공배수)-python3 (0) | 2023.11.24 |
백준-2606번(바이러스)-python3 (0) | 2023.11.24 |