t | def updnm(num): | t | def updnm(num): |
| if num == 9: | | if num == 9: |
| return 0 | | return 0 |
| return num + 1 | | return num + 1 |
| | | |
| def spiral(): | | def spiral(): |
| N, M = map(int, input().split(',')) | | N, M = map(int, input().split(',')) |
| arr = [[-1 for _ in range(N)] for _ in range(M)] | | arr = [[-1 for _ in range(N)] for _ in range(M)] |
| left, right, top, bottom = (0, N - 1, 0, M - 1) | | left, right, top, bottom = (0, N - 1, 0, M - 1) |
| num = 0 | | num = 0 |
| while left <= right and top <= bottom: | | while left <= right and top <= bottom: |
| for i in range(left, right + 1): | | for i in range(left, right + 1): |
| arr[top][i] = num | | arr[top][i] = num |
| num = updnm(num) | | num = updnm(num) |
| top += 1 | | top += 1 |
| for i in range(top, bottom + 1): | | for i in range(top, bottom + 1): |
| arr[i][right] = num | | arr[i][right] = num |
| num = updnm(num) | | num = updnm(num) |
| right -= 1 | | right -= 1 |
| if top <= bottom: | | if top <= bottom: |
| for i in range(right, left - 1, -1): | | for i in range(right, left - 1, -1): |
| arr[bottom][i] = num | | arr[bottom][i] = num |
| num = updnm(num) | | num = updnm(num) |
| bottom -= 1 | | bottom -= 1 |
| if left <= right: | | if left <= right: |
| for i in range(bottom, top - 1, -1): | | for i in range(bottom, top - 1, -1): |
| arr[i][left] = num | | arr[i][left] = num |
| num = updnm(num) | | num = updnm(num) |
| left += 1 | | left += 1 |
| for row in arr: | | for row in arr: |
| print(' '.join(map(str, row))) | | print(' '.join(map(str, row))) |
| if __name__ == '__main__': | | if __name__ == '__main__': |
| spiral() | | spiral() |