๋ฌธ์
๋ฐฑ์ค ์จ๋ผ์ธ ์ ์ง - 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 |
๐ฌ ๋๊ธ