접근 방법
- dfs 재귀호출 횟수를 체크
import sys
n = int(input())
graph = [list(map(int, input())) for _ in range(n)]
def dfs(x, y):
if x < 0 or x >= n or y < 0 or y >= n:
return 0
if graph[x][y]:
graph[x][y] = 0
count = 1
count += dfs(x-1, y)
count += dfs(x, y-1)
count += dfs(x+1, y)
count += dfs(x, y+1)
return count
return 0
answer = []
for i in range(n):
for j in range(n):
res = dfs(i, j)
if res:
answer.append(res)
print(len(answer))
answer.sort()
for a in answer:
print(a)