Coding Test/softeer

[소프티어] 조립라인 - python (레벨 3)

조용장 2022. 4. 28. 01:11

https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=403 

 

Softeer

연습문제를 담을 Set을 선택해주세요. 취소 확인

softeer.ai

풀이

문제를 보았을때 알수있는 힌트

문제를 보고 오! 이거 그냥 반복문 써서 작은 것을 찾으면 되겠지 싶을 수도 있다. 아마 그렇게 하면.. 시간초과가 나지 않을까 싶다.

문제를 좀더 이해하면서 풀면 a에서 작업을 하고 b로 이동시간을 더하고 그게 b에서 작업한것과 비교하고 반대의 경우를 비교하여 계산을 반복하면 쉽게 문제가 풀린다.

import sys

input= sys.stdin.readline

n = int(input())
# a,b 라인의 처음
a,b=0,0
for i in range(n-1):
    a1,b1,c1,d1 = map(int,input().split())
    temp_b=min(a1+c1+a,b1+b) # b 라인의 최소값
    temp_a=min(b1+d1+b,a1+a) # a 라인의 최소값
    a= temp_a
    b= temp_b
c,d=map(int,input().split())
a+=c
b+=d
print(min(a,b))

https://github.com/dydwkd486/coding_test/blob/main/softeer/조립라인.py 

 

GitHub - dydwkd486/coding_test: 코딩테스트 공부한 내용 정리

코딩테스트 공부한 내용 정리. Contribute to dydwkd486/coding_test development by creating an account on GitHub.

github.com