From fdd1a53d87c20b7e9e5e872d824437310bff8a3d Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sat, 14 Feb 2026 19:09:55 +0900 Subject: [PATCH] baekjoon 20260214 --- code_study/Baekjoon/python/14924.py | 1 + code_study/Baekjoon/python/2342_1.py | 29 ++++++++++++++++++++++++ code_study/Baekjoon/python/2342_2.py | 34 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 code_study/Baekjoon/python/14924.py create mode 100644 code_study/Baekjoon/python/2342_1.py create mode 100644 code_study/Baekjoon/python/2342_2.py diff --git a/code_study/Baekjoon/python/14924.py b/code_study/Baekjoon/python/14924.py new file mode 100644 index 0000000..bd7c126 --- /dev/null +++ b/code_study/Baekjoon/python/14924.py @@ -0,0 +1 @@ +print((lambda x : (x[2] // (2*x[0]))*x[1])(list(map(int, input().split())))) \ No newline at end of file diff --git a/code_study/Baekjoon/python/2342_1.py b/code_study/Baekjoon/python/2342_1.py new file mode 100644 index 0000000..1594bc9 --- /dev/null +++ b/code_study/Baekjoon/python/2342_1.py @@ -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)) \ No newline at end of file diff --git a/code_study/Baekjoon/python/2342_2.py b/code_study/Baekjoon/python/2342_2.py new file mode 100644 index 0000000..4b42b87 --- /dev/null +++ b/code_study/Baekjoon/python/2342_2.py @@ -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]) \ No newline at end of file