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

BOJ 17406 - ๋ฐฐ์—ด ๋Œ๋ฆฌ๊ธฐ 4

by HandHand 2021. 3. 18.

๋ฌธ์ œ

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

ํ’€์ด ๊ณผ์ •

์ฃผ์–ด์ง„ ์กฐ๊ฑด๋Œ€๋กœ ๋ฐฐ์—ด A ๋ฅผ ๋Œ๋ฆฌ๋ฉฐ ๋ฐฐ์—ด์˜ ์ตœ์†Œ๊ฐ’์„ ์ฐพ๋Š” ๋ธŒ๋ฃจํŠธํฌ์Šค ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

ํšŒ์ „ ์—ฐ์‚ฐ์˜ ๊ฐœ์ˆ˜ K ๊ฐ€ ํฌ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ˆœ์—ด์„ ์ƒ์„ฑํ•˜๊ณ  ๋ชจ๋“  ๊ฒฝ์šฐ์— ๋Œ€์‘ํ•ด์„œ ์ตœ์†Œ๊ฐ’์„ ์ฐพ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys
import copy
from itertools import permutations

N, M, K = list(map(int, sys.stdin.readline().split()))
board = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
operation = [list(map(int, sys.stdin.readline().split())) for _ in range(K)]


def rotate(board, sx, sy, offset):
    while offset > 0:
        left_top_pos = [sx - offset, sy - offset]
        right_bottom_pos = [sx + offset, sy + offset]

        temp = board[left_top_pos[0] - 1][left_top_pos[1] - 1]

        for x in range(left_top_pos[0], right_bottom_pos[0]):
            board[x - 1][left_top_pos[1] - 1] = board[x][left_top_pos[1] - 1]

        for y in range(left_top_pos[1], right_bottom_pos[1]):
            board[right_bottom_pos[0] - 1][y - 1] = board[right_bottom_pos[0] - 1][y]

        for x in range(right_bottom_pos[0], left_top_pos[0], -1):
            board[x - 1][right_bottom_pos[1] - 1] = board[x - 2][right_bottom_pos[1] - 1]

        for y in range(right_bottom_pos[1], left_top_pos[1], -1):
            board[left_top_pos[0] - 1][y - 1] = board[left_top_pos[0] - 1][y - 2]

        board[left_top_pos[0] - 1][left_top_pos[1]] = temp

        offset -= 1


def get_array_value(board):
    ret = sys.maxsize
    for row in board:
        ret = min(ret, sum(row))
    return ret


def solution():
    answer = sys.maxsize

    for perms in permutations(operation):
        rotated_board = copy.deepcopy(board)
        for perm in perms:
            rotate(rotated_board, *perm)
        answer = min(answer, get_array_value(rotated_board))

    return answer


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

'๐Ÿƒ algorithm > boj' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ 14716 - ํ˜„์ˆ˜๋ง‰  (0) 2021.03.18
BOJ 14923 - ๋ฏธ๋กœ ํƒˆ์ถœ  (0) 2021.03.18
BOJ 1543 - ๋ฌธ์„œ ๊ฒ€์ƒ‰  (0) 2021.03.18
BOJ 11403 - ๊ฒฝ๋กœ ์ฐพ๊ธฐ  (0) 2021.03.18
BOJ 18243 - Small World Network  (0) 2021.03.18

๐Ÿ’ฌ ๋Œ“๊ธ€