baekjoon 20260214

This commit is contained in:
songyc macbook 2026-02-14 19:09:55 +09:00
parent 1dd473dccc
commit fdd1a53d87
3 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1 @@
print((lambda x : (x[2] // (2*x[0]))*x[1])(list(map(int, input().split()))))

View File

@ -0,0 +1,29 @@
import sys
sys.setrecursionlimit(10**6)
force = [
[1,2,2,2,2],
[2,1,3,4,3],
[2,3,1,3,4],
[2,4,3,1,3],
[2,3,4,3,1]
]
seq = list(map(int, input().split()))
n = len(seq)
inf = float("inf")
dp = [[[inf]*5 for _ in range(5)] for _ in range(n)]
def dfs(L, R, step) :
target = seq[step]
if target == 0 :
return 0
if dp[step][L][R] == inf :
moveLeft = dfs(target, R, step+1) + force[L][target]
moveRight = dfs(L, target, step+1) + force[R][target]
dp[step][L][R] = min([moveLeft, moveRight])
return dp[step][L][R]
print(dfs(0,0,0))

View File

@ -0,0 +1,34 @@
force = [
[1,2,2,2,2],
[2,1,3,4,3],
[2,3,1,3,4],
[2,4,3,1,3],
[2,3,4,3,1]
]
seq = list(map(int, input().split()))
n = len(seq)
inf = float("inf")
dp = [[[inf]*5 for _ in range(5)] for _ in range(2)]
for i in range(5) :
for j in range(5) :
dp[1][i][j] = 0
cur_idx = 0
nxt_idx = 1
for step in range(n-1,-1, -1) :
target = seq[step]
if target == 0 :
continue
for l in range(5) :
for r in range(5) :
moveLeft = dp[nxt_idx][target][r] + force[l][target]
moveRight = dp[nxt_idx][l][target] + force[r][target]
dp[cur_idx][l][r] = min(moveLeft, moveRight)
cur_idx = 1 if cur_idx == 0 else 0
nxt_idx = 1 if cur_idx == 0 else 0
print(dp[nxt_idx][0][0])