백준 3256 비행기 / python

이유참치·2026년 2월 22일

백준

목록 보기
224/248

문제 : 3256

풀이 point

13335 문제랑 비슷하다. 문제 설명 그대로 구현하면 된다.

행 기준으로 도착했을 때 5초를 세주는 로직만 잘 셀수 있도록 주의하면 좋다.

풀이 코드

N = int(input())

passengers = []

for _ in range(N):
  passengers.append(int(input()))

passengers.reverse()

L = max(passengers)

check = [None]*(L+1)

time = 0
while passengers or any(check[1:]):
  if check[1] is None and passengers:
    check[1] = [passengers.pop(), -1]
  
  for i in range(L, 0, -1):
    if check[i] is not None:
      if check[i][0] == i:
        if check[i][1] == -1:
          check[i][1] = 5
        check[i][1] -= 1
        if check[i][1] == 0:
          check[i] = None
      else:
        if i < L and check[i+1] is None:
          check[i+1] = check[i]
          check[i] = None
  time += 1

print(time)
profile
임아리 - 대학생

0개의 댓글