-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1926.py
More file actions
44 lines (32 loc) · 844 Bytes
/
1926.py
File metadata and controls
44 lines (32 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
input = sys.stdin.readline
from collections import deque
n, m = map(int, input().split())
paper = [list(map(int, input().split())) for _ in range(n)]
visited = [[False] * m for _ in range(n)]
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
def bfs(sx, sy, visited):
visited[sx][sy] = True
q = deque([(sx, sy)])
area = 1
while q:
x, y = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < n and 0 <= ny < m:
if not visited[nx][ny] and paper[nx][ny] == 1:
q.append((nx, ny))
visited[nx][ny] = True
area += 1
return area
drawingNum = 0
maxArea = 0
for i in range(n):
for j in range(m):
if paper[i][j] == 1 and not visited[i][j]:
maxArea = max(maxArea, bfs(i, j, visited))
drawingNum += 1
print(drawingNum)
print(maxArea)