-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaek_2667.py
More file actions
41 lines (35 loc) · 860 Bytes
/
Baek_2667.py
File metadata and controls
41 lines (35 loc) · 860 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
import sys
n = int(sys.stdin.readline())
a = []
an = []
for i in range(n):
f = sys.stdin.readline()
for j in range(len(f)):
if f[j] == "1":
a.append((i,j))
while a:
b = []
c = []
c.append(a[0])
del a[0]
while c:
d = c[0]
del c[0]
b.append(d)
if (d[0]+1,d[1]) in a:
c.append((d[0]+1,d[1]))
a.remove((d[0]+1,d[1]))
if (d[0]-1,d[1]) in a:
c.append((d[0]-1,d[1]))
a.remove((d[0]-1,d[1]))
if (d[0],d[1]+1) in a:
c.append((d[0],d[1]+1))
a.remove((d[0],d[1]+1))
if (d[0],d[1]-1) in a:
c.append((d[0],d[1]-1))
a.remove((d[0],d[1]-1))
an.append(len(b))
an.sort()
print(len(an))
for i in range(len(an)):
print(an[i])