From b904ecc29b76f6562f45232e0a0a160320ff5568 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Tue, 19 Aug 2025 18:06:51 +0900 Subject: [PATCH] =?UTF-8?q?[20250819]=20BOJ=20/=20G4=20/=20=EC=9D=B4?= =?UTF-8?q?=EB=AA=A8=ED=8B=B0=EC=BD=98=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64\353\252\250\355\213\260\354\275\230.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "Ukj0ng/202508/19 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" diff --git "a/Ukj0ng/202508/19 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" "b/Ukj0ng/202508/19 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" new file mode 100644 index 00000000..6cab66c2 --- /dev/null +++ "b/Ukj0ng/202508/19 BOJ G4 \354\235\264\353\252\250\355\213\260\354\275\230.md" @@ -0,0 +1,60 @@ +``` +import java.io.*; +import java.util.ArrayDeque; +import java.util.HashSet; +import java.util.Queue; +import java.util.Set; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static Set visited; + private static int S; + public static void main(String[] args) throws IOException { + init(); + int answer = BFS(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + S = Integer.parseInt(br.readLine()); + visited = new HashSet<>(); + } + + private static int BFS() { + Queue q = new ArrayDeque<>(); + int time = 0; + visited.add(1+","+0); + // 이모티콘 개수, 클립보드 개수, 시간 + q.add(new int[]{1, 0, time}); + + while (!q.isEmpty()) { + int[] current = q.poll(); + if (current[0] == S) { + time = current[2]; + break; + } + + for (int i = 0; i < 3; i++) { + if (i == 0) { + q.add(new int[]{current[0], current[0], current[2]+1}); + } else if (i == 1 && current[1] > 0) { + if (visited.contains(current[0]+current[1] + "," + current[1])) continue; + visited.add(current[0]+current[1] + "," + current[1]); + q.add(new int[]{current[0]+current[1], current[1], current[2]+1}); + } else { + if (current[0]-1<0 || visited.contains(current[0]-1 + "," + current[1])) continue; + visited.add(current[0]-1 + "," + current[1]); + q.add(new int[]{current[0]-1, current[1], current[2]+1}); + } + } + } + + return time; + } +} +```