PS/백준
[Python] 17266번 어두운 굴다리
s_omi
2024. 7. 30. 09:32
✏️ 문제
문제 파악
이건 경우의 수를 위치를 기준으로 3가지로 나눠서 생각해야 한다.
- 0 위치 ~ 가로등[0]의 위치
- 가로등[a]의 위치 ~ 가로등[a+1]의 위치
- 가로등[m-1]의 위치 ~ n 위치
알고리즘
- 구현
- 이분 탐색
코드
import sys
input = sys.stdin.readline
n = int(input())
m = int(input())
location = list(map(int, input().split()))
length = 0
if m == 1:
length = max(location[0], n - location[0])
else:
for i in range(m):
if i == 0:
x = location[i]
elif i == m-1:
x = n - location[i]
else:
distance = location[i] - location[i-1]
if distance % 2 == 0:
x = distance // 2
else:
x = distance // 2 + 1
length = max(x, length)
print(length)