|
| 1 | +from typing import List |
| 2 | + |
| 3 | + |
| 4 | +def solution(n: int, m: int, r: int, arr: List[List[int]]) -> List[List[int]]: |
| 5 | + def rotate(): |
| 6 | + check: int = min(n, m) // 2 |
| 7 | + |
| 8 | + for cnt in range(check): |
| 9 | + n_max, m_max = n - cnt - 1, m - cnt - 1 |
| 10 | + tmp: int = arr[cnt][cnt] |
| 11 | + |
| 12 | + # 위쪽 변 |
| 13 | + for i in range(cnt, m_max): |
| 14 | + arr[cnt][i] = arr[cnt][i + 1] |
| 15 | + |
| 16 | + # 오른쪽 변 |
| 17 | + for i in range(cnt, n_max): |
| 18 | + arr[i][m_max] = arr[i + 1][m_max] |
| 19 | + |
| 20 | + # 아래쪽 변 |
| 21 | + for i in range(m_max, cnt, -1): |
| 22 | + arr[n_max][i] = arr[n_max][i - 1] |
| 23 | + |
| 24 | + # 왼쪽 변 |
| 25 | + for i in range(n_max, cnt, -1): |
| 26 | + arr[i][cnt] = arr[i - 1][cnt] |
| 27 | + |
| 28 | + arr[cnt + 1][cnt] = tmp |
| 29 | + |
| 30 | + for _ in range(r): |
| 31 | + rotate() |
| 32 | + |
| 33 | + return arr |
| 34 | + |
| 35 | + |
| 36 | +if __name__ == "__main__": |
| 37 | + N, M, R = map(int, input().split()) |
| 38 | + arr: List[List[int]] = [] |
| 39 | + |
| 40 | + for _ in range(N): |
| 41 | + arr.append(list(map(int, input().split()))) |
| 42 | + |
| 43 | + answer: List[List[int]] = solution(N, M, R, arr) |
| 44 | + |
| 45 | + for row in answer: |
| 46 | + print(" ".join([str(num) for num in row])) |
| 47 | + |
0 commit comments