https://www.acmicpc.net/problem/17406
특정 알고리즘을 사용하는 것이 아닌 단순 구현에 관한 문제였다.
배열을 돌릴때 배열을 이동시키는 과정에서 값들의 저장이 필요함을 알았고,
각 코너부분을 미리 저장해놓고, 우선 돌린뒤 코너부분이 들어가야 하는 부분에 넣어주었다.
from itertools import permutations
import copy
import math
n,m,k = list(map(int,input().split()))
graph = []
for i in range(n):
graph.append(list(map(int,input().split())))
rotations = []
for i in range(k):
rotations.append(list(map(int,input().split())))
answer = math.inf
def do_rotate(graph,r,c,s):
for i in range(1,s+1):
left_top = graph[r-i][c-i]
right_top = graph[r-i][c+i]
left_bottom = graph[r+i][c-i]
right_bottom = graph[r+i][c+i]
for j in range(2*i):
graph[r-i][c+i-j] = graph[r-i][c+i-j-1]
graph[r+i-j][c+i] = graph[r+i-j-1][c+i]
graph[r+i][c-i+j] = graph[r+i][c-i+j+1]
graph[r-i+j][c-i] = graph[r-i+j+1][c-i]
graph[r-i+1][c+i] = right_top
graph[r+i][c+i-1] = right_bottom
graph[r+i-1][c-i] = left_bottom
graph[r-i][c-i+1] = left_top
return graph
rotation_combination = list(permutations(range(k),k))
for r in rotation_combination:
board = copy.deepcopy(graph)
for e in r:
board = do_rotate(board,rotations[e][0]-1,rotations[e][1]-1,rotations[e][2])
for row in board:
answer = min(answer,sum(row))
print(answer)