๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿƒ algorithm/boj

BOJ 16926 - ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 1

by HandHand 2021. 4. 13.

๋ฌธ์ œ

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ - 16926๋ฒˆ

ํ’€์ด ๊ณผ์ •

๋ฐฐ์—ด์„ ํšŒ์ „ํ•˜๋Š” ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
python ์œผ๋กœ ์ œ์ถœํ•˜๋‹ˆ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•˜์—ฌ pypy3 ๋กœ ์ œ์ถœํ–ˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys


def rotate():
    x, y = 0, 0
    n, m = N, M
    time = min(N, M) // 2

    while time:
        cache = board[x][y]

        # ์œ—์ชฝ
        for i in range(m - 1):
            board[x][y + i] = board[x][y + i + 1]

        # ์˜ค๋ฅธ์ชฝ
        for i in range(n - 1):
            board[x + i][y + m - 1] = board[x + i + 1][y + m - 1]

        # ์•„๋ž˜์ชฝ
        for i in range(m - 1):
            board[x + n - 1][y + m - 1 - i] = board[x + n - 1][y + m - 2 - i]

        # ์™ผ์ชฝ
        for i in range(n - 1):
            board[x + n - 1 - i][y] = board[x + n - 2 - i][y]
        board[x + 1][y] = cache

        n -= 2
        m -= 2
        x += 1
        y += 1
        time -= 1


def solution():
    for _ in range(R):
        rotate()

    for row in board:
        print(*row)


if __name__ == '__main__':
    N, M, R = list(map(int, sys.stdin.readline().split()))
    board = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

    solution()
๋ฐ˜์‘ํ˜•

๐Ÿ’ฌ ๋Œ“๊ธ€