BOJ - 4883 - 삼각 그래프
Updated:
import sys
def solution():
testCase = 0
while True:
T = int(sys.stdin.readline())
if not T:
break
left, mid, right = map(int, sys.stdin.readline().split())
start = mid
dLeft = 0
dMid = mid
dRight = mid + right
left, mid, right = map(int, sys.stdin.readline().split())
dLeft = dMid + left
dMid = min(min(dLeft, dMid), dRight) + mid
dRight = min(min(dMid, dRight), start) + right
for i in range(0, T-2):
left, mid, right = map(int, sys.stdin.readline().split())
tempLeft = dLeft
tempMid = dMid
dLeft = min(dLeft, dMid) + left;
dMid = min(min(min(dLeft, dMid), dRight), tempLeft) + mid;
dRight = min(min(dMid, dRight), tempMid) + right
testCase += 1
print("{}. {}".format(testCase, dMid))
solution()
https://www.acmicpc.net/problem/4883
Leave a comment