'''
10,10
0,0,0,0,0,0,0,0,0,0
0,0,0,1,1,0,1,0,0,0
0,1,0,0,0,0,0,1,0,1
1,0,0,0,0,0,0,0,1,1
0,0,0,1,1,1,0,0,0,1
0,0,0,0,0,0,1,0,1,1
0,1,1,0,0,0,0,0,0,0
0,0,0,1,0,1,0,0,0,0
0,0,1,0,0,1,0,0,0,0
0,1,0,0,0,0,0,0,0,0
output
6,8
'''
import sys
option = [(-1, -1), (-1, 0), (0, -1), (1, -1), (-1, +1), (0, +1), (+1, +1), (+1, 0)]
def get_max_num(list_num, m, n):
list_temp = [[0 for i in range(m)] for j in range(n)]
stacks = []
P = 0
Q = 0
q = 0
for i in range(m):
for j in range(n):
if list_num[i][j] == 1 and list_temp[i][j] == 1:
continue
if list_num[i][j] == 1 and list_temp[i][j] == 0:
P += 1
# print((i,j))
list_temp[i][j] = 1
q += 1
for s in option:
if (i + s[0]) < m and (j + s[1]) < n \
and (i + s[0]) >= 0 and (j + s[1]) >= 0:
if list_num[i + s[0]][j + s[1]] == 1 and list_temp[i + s[0]][j + s[1]] != 1:
stacks.append((i + s[0], j + s[1]))
q += 1
# print(stacks)
while(stacks):
list_n = []
for stack_index in range(len(stacks)):
st = stacks[stack_index]
list_temp[st[0]][st[1]] = 1
for s in option:
if (st[0] + s[0]) < m and (st[1] + s[1]) < n \
and (st[0] + s[0]) >= 0 and (st[1] + s[1]) >= 0:
if list_num[st[0] + s[0]][st[1] + s[1]] == 1 \
and list_temp[st[0] + s[0]][st[1] + s[1]] == 0:
if(st[0] + s[0], st[1] + s[1]) not in stacks:
stacks.append((st[0] + s[0], st[1] + s[1]))
q += 1
list_n.append(stack_index)
# print(stacks, list_n)
list_n.sort(reverse = True)
for ls in list_n:
stacks.pop(ls)
Q = max(Q, q)
q = 0
return P, Q
if __name__ == "__main__":
m, n = sys.stdin.readline().strip().split(',')
list_num = []
for i in range(int(m)):
# 读取每一行
line = sys.stdin.readline().strip()
# 把每一行的数字分隔后转化成int列表
values = list(map(int, line.split(',')))
list_num.append(values)
if m == 0 and n == 0:
print('0,0')
else:
a, b = get_max_num(list_num, int(m), int(n))
print(str(a)+','+str(b))
80...就是过不去