r, c = map(int, raw_input().split())
data = [0] * r
for i in range(r):
data[i] = list(raw_input())
def getSzField(field):
ret = [[-2 for i in range(len(field[0]))] for j in range(len(field))]
movs = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for i in range(len(field)):
for j in range(len(field[0])):
if ret[i][j] == -2:
q = [(i, j)]
qi = 0
ret[i][j] = -3
while qi < len(q):
y, x = q[qi]
for mov in movs:
ny = y + mov[0]
nx = x + mov[1]
if ny >= 0 and ny < len(field) and nx >= 0 and nx < len(field[0]) and field[ny][nx] == field[y][x] and ret[ny][nx] == -2:
ret[ny][nx] = -3
q += [(ny, nx)]
qi += 1
for coord in q:
ret[coord[0]][coord[1]] = len(q)
return ret
sField = [[0 for j in range(3 * c)] for i in range(3 * r)]
for i in range(3 * r):
for j in range(3 * c):
sField[i][j] = data[i % r][j % c]
ssz = getSzField(sField)
lField = [[0 for j in range(4 * c)] for i in range(4 * r)]
for i in range(4 * r):
for j in range(4 * c):
lField[i][j] = data[i % r][j % c]
lsz = getSzField(lField)
for i in range(r):
for j in range(c):
if ssz[r + i][c + j] == lsz[r * 2 + i][c * 2 + j] and ssz[r + i][c + j] == lsz[r + i][c + j]:
print ssz[r + i][c + j],
else:
print -1,
print
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1044 ms |
101 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |