From 4833179212b84867bd38df9d416a628fa6fdadaa Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sun, 9 Nov 2025 21:42:09 +0900 Subject: [PATCH] =?UTF-8?q?[20251109]=20PGM=20/=20LV2=20/=20=EC=88=AB?= =?UTF-8?q?=EC=9E=90=20=EB=B3=80=ED=99=98=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\355\231\230\355\225\230\352\270\260.md" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "LiiNi-coder/202511/09 PGM \354\210\253\354\236\220 \353\263\200\355\231\230\355\225\230\352\270\260.md" diff --git "a/LiiNi-coder/202511/09 PGM \354\210\253\354\236\220 \353\263\200\355\231\230\355\225\230\352\270\260.md" "b/LiiNi-coder/202511/09 PGM \354\210\253\354\236\220 \353\263\200\355\231\230\355\225\230\352\270\260.md" new file mode 100644 index 00000000..4bd57f86 --- /dev/null +++ "b/LiiNi-coder/202511/09 PGM \354\210\253\354\236\220 \353\263\200\355\231\230\355\225\230\352\270\260.md" @@ -0,0 +1,36 @@ +```java +import java.util.*; + +class Solution { + private static int MAX = 1_000_001; + public int solution(int x, int y, int n) { + int answer = 0; + Queue q = new ArrayDeque(); + q.offer(new int[]{0, x}); + boolean[] visited = new boolean[MAX]; + visited[x] = true; + boolean hasAnswer = false; + int count = 0, value; + while(!q.isEmpty()){ + int[] temp = q.poll(); + count = temp[0]; + value = temp[1]; + if(value == y){ + hasAnswer = true; + break; + } + for(int new_value: new int[]{value+n, value*2, value*3}){ + if(new_value >= MAX){ + continue; + } + if(visited[new_value]) + continue; + q.offer(new int[]{count+1, new_value}); + visited[new_value] = true; + } + + } + return (hasAnswer)? count: -1; + } +} +```