From fb87766235063e0e1941ae55a75c9ea78824919c Mon Sep 17 00:00:00 2001 From: oncsr Date: Tue, 11 Feb 2025 16:37:35 +0900 Subject: [PATCH] =?UTF-8?q?[20250211]=20BOJ=20/=20=ED=94=8C=EB=9E=985=20/?= =?UTF-8?q?=20=EB=AC=BC=EC=95=BD=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../11 BOJ P5 \353\254\274\354\225\275.md" | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 "khj20006/202502/11 BOJ P5 \353\254\274\354\225\275.md" diff --git "a/khj20006/202502/11 BOJ P5 \353\254\274\354\225\275.md" "b/khj20006/202502/11 BOJ P5 \353\254\274\354\225\275.md" new file mode 100644 index 00000000..a98be617 --- /dev/null +++ "b/khj20006/202502/11 BOJ P5 \353\254\274\354\225\275.md" @@ -0,0 +1,122 @@ +```java + +import java.util.*; +import java.io.*; + +class Node { + int cnt; + String ingredient; + Node(int cnt, String ingredient){ + this.cnt = cnt; + this.ingredient = ingredient; + } +} + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + static final int INF = 1000000001; + + static int N, M; + static HashMap price = new HashMap<>(); + static String[] newIngredients; + static List[] expressions; + static boolean[] clear; + + public static void main(String[] args) throws Exception { + + ready(); + solve(); + + bwEnd(); + } + + static void ready() throws Exception{ + + nextLine(); + N = nextInt(); + M = nextInt(); + for(int i=0;i(); + for(int j=0;j= INF) break; + int value = price.get(node.ingredient); + for(int k=0;k= INF) { + res = INF; + break; + } + res += value; + } + } + if(price.containsKey(newIngredients[i])) { + if(res < price.get(newIngredients[i])) { + price.put(newIngredients[i], res); + change = true; + + } + } + else { + price.put(newIngredients[i], res); + change = true; + } + + + } + + }while(change); + + if(price.containsKey("LOVE")) bw.write(price.get("LOVE")+"\n"); + else bw.write("-1"); + + } + + +} + +```