Skip to content

Commit 2ac22bc

Browse files
committed
[BOJ] #2564. 경비원 / 실버1 / 60분 / 실패
1 parent 8b08e1e commit 2ac22bc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 1. 입력받기
5+
w, h = map(int, input().split()) # 가로, 세로
6+
store_cnt = int(input()) # 상점의 개수
7+
8+
# 2. 둘레 계산
9+
perimeter = 2 * (w + h)
10+
11+
# 3. (방향, 거리) -> 1차원 위치로 변환 함수
12+
def to_pos(dir, dist):
13+
if dir == 1: # 북
14+
return dist
15+
if dir == 2: # 남
16+
return w + h + (w - dist)
17+
if dir == 3: # 서
18+
return 2*w + h + (h - dist)
19+
if dir == 4: # 동
20+
return w + dist
21+
22+
23+
# 4. 모든 상점의 위치를 1차원 조표로 변환해서 리스트에 모으기
24+
store_loc = [] # 상점의 위치
25+
for _ in range(store_cnt):
26+
d, dist = map(int, input().split())
27+
store_loc.append(to_pos(d, dist))
28+
29+
# 5. 경비원 위치도 똑같이 변환
30+
gd, gdist = map(int, input().split())
31+
guard_pos = to_pos(gd, gdist)
32+
33+
# print(f"store: {store_loc}")
34+
# print(f"guard: {guard_pos}")
35+
36+
# 6. 각 상점까지 최단 거리 구해서 합산
37+
total = 0
38+
for store in store_loc:
39+
diff = abs(store - guard_pos)
40+
# 시계방향 <-> 반시계방향 중 짧은 거리 선택
41+
total += min(diff, perimeter - diff)
42+
43+
# 7. 결과 출력
44+
print(total)

0 commit comments

Comments
 (0)