BOJ - 2096 - 내려가기
Updated:
import sys
def solution():
dx = [0, 1, -1, 1]
dy = [1, 0, 1, 1]
N = int(input())
maps = []
for _ in range(N):
maps.append(list(map(int, sys.stdin.readline().split())))
minLeft = maps[0][0]
minMid = maps[0][1]
minRight = maps[0][2]
maxLeft = maps[0][0]
maxMid = maps[0][1]
maxRight = maps[0][2]
for i in range(1, N):
temp = [0] * 6
temp[0] = max(maxLeft, maxMid) + maps[i][0]
temp[1] = max(maxLeft, maxMid, maxRight) + maps[i][1]
temp[2] = max(maxMid, maxRight) + maps[i][2]
temp[3] = min(minLeft, minMid) + maps[i][0]
temp[4] = min(minLeft, minMid, minRight) + maps[i][1]
temp[5] = min(minMid, minRight) + maps[i][2]
maxLeft = temp[0]
maxMid = temp[1]
maxRight = temp[2]
minLeft = temp[3]
minMid = temp[4]
minRight = temp[5]
print("{0} {1}".format(
max(maxLeft, maxMid, maxRight),
min(minLeft, minMid, minRight)
))
solution()
https://www.acmicpc.net/problem/2096
Leave a comment