From fbbbaeb8e6cf54fe615d5bd9c58709ec38996f19 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Wed, 31 Dec 2025 22:01:12 +0900 Subject: [PATCH] baekjoon 20251231 --- code_study/Baekjoon/java/_2342.java | 52 +++++++++++++++++++++++++++ code_study/Baekjoon/java/_2342_1.java | 42 ++++++++++++++++++++++ code_study/Baekjoon/python/5596.py | 1 + 3 files changed, 95 insertions(+) create mode 100644 code_study/Baekjoon/java/_2342.java create mode 100644 code_study/Baekjoon/java/_2342_1.java create mode 100644 code_study/Baekjoon/python/5596.py diff --git a/code_study/Baekjoon/java/_2342.java b/code_study/Baekjoon/java/_2342.java new file mode 100644 index 0000000..965643d --- /dev/null +++ b/code_study/Baekjoon/java/_2342.java @@ -0,0 +1,52 @@ +import java.util.*; + +public class _2342 { + static int INF = Integer.MAX_VALUE; + static int[][] move_energy = { + {0,2,2,2,2}, + {0,1,3,4,3}, + {0,3,1,3,4}, + {0,4,3,1,3}, + {0,3,4,3,1} + }; + static int[][][] dp = new int[2][5][5]; + static int curr = 0, next = 1; + + static void swap() { + int temp = curr; + curr = next; + next = temp; + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int[] inst = Arrays.stream(sc.nextLine().split(" ")) + .mapToInt(Integer::parseInt) + .toArray(); + sc.close(); + + for(int i=0; i<2; i++) { + for(int l=0; l<5; l++) { + for(int r=0; r<5; r++) { + if(i==0) dp[i][l][r] = INF; + else dp[i][l][r] = 0; + } + } + } + + for(int i=inst.length-2; i>=0; i--) { + int target = inst[i]; + for(int L=0; L<5; L++) { + for(int R=0; R<5; R++) { + int moveLeft = dp[next][target][R] + move_energy[L][target]; + int moveRight = dp[next][L][target] + move_energy[R][target]; + + dp[curr][L][R] = Math.min(moveLeft, moveRight); + } + } + swap(); + } + + System.out.println(dp[next][0][0]); + } +} \ No newline at end of file diff --git a/code_study/Baekjoon/java/_2342_1.java b/code_study/Baekjoon/java/_2342_1.java new file mode 100644 index 0000000..3861402 --- /dev/null +++ b/code_study/Baekjoon/java/_2342_1.java @@ -0,0 +1,42 @@ +import java.util.*; + +public class _2342_1 { + static int[][][] dp; + static int[] inst; + static int inst_num; + static int[][] move_energy = { + {1,2,2,2,2}, + {0,1,3,4,3}, + {0,3,1,3,4}, + {0,4,3,1,3}, + {0,3,4,3,1} + }; + + static int solve(int L, int R, int step) { + if(step == inst_num) return 0; + + if(dp[step][L][R] == 0) { + int target = inst[step]; + + int moveLeft = solve(target, R, step+1) + move_energy[L][target]; + int moveRight = solve(L, target, step+1) + move_energy[R][target]; + + dp[step][L][R] = Math.min(moveLeft, moveRight); + } + + return dp[step][L][R]; + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + inst = Arrays.stream(sc.nextLine().split(" ")) + .mapToInt(Integer::parseInt) + .toArray(); + sc.close(); + + inst_num = inst.length-1; + dp = new int[inst_num][5][5]; + + System.out.println(solve(0, 0, 0)); + } +} \ No newline at end of file diff --git a/code_study/Baekjoon/python/5596.py b/code_study/Baekjoon/python/5596.py new file mode 100644 index 0000000..11f7b03 --- /dev/null +++ b/code_study/Baekjoon/python/5596.py @@ -0,0 +1 @@ +print(max([sum(list(map(int, input().split()))) for _ in range(2)])) \ No newline at end of file