방향, 거리에따른 위치 변환 후 계산
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
K = int(input())
store = []
for _ in range(K):
store_dir, dist = map(int, input().split())
if store_dir==1:
y = M
x = dist
elif store_dir==2:
y=0
x = dist
elif store_dir==3:
x=0
y=M-dist
else:
x=N
y = M-dist
store.append([x,y])
dongguen_dir, dist = map(int, input().split())
if dongguen_dir==1:
y = M
x = dist
elif dongguen_dir==2:
y=0
x = dist
elif dongguen_dir==3:
x=0
y=M-dist
else:
x=N
y = M-dist
answer = 0
for store_x,store_y in store:
if not abs(store_x-x) == N and not abs(store_y-y)==M:
answer += abs(store_x-x) + abs(store_y-y)
else:
answer += min(x+y+store_x+store_y,2*N+2*M-(x+y+store_x+store_y))
print(answer)
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 13913 숨바꼭질4 (0) | 2021.08.29 |
---|---|
[백준][Python] 2581 소수 (0) | 2021.08.29 |
[백준][Python] 2605 줄세우기 (0) | 2021.08.29 |
[백준][Python] 14696 딱지놀이 (0) | 2021.08.29 |
[백준][Python] 13300 방배정 (0) | 2021.08.29 |