From 197b23193d56d48186cef9cf62d85037bac687b0 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Thu, 18 Sep 2025 20:11:20 +0900 Subject: [PATCH] =?UTF-8?q?[20250918]=20BOJ=20/=20G4=20/=20=EB=A6=AC?= =?UTF-8?q?=EB=AA=A8=EC=BB=A8=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\246\254\353\252\250\354\273\250.md" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "lkhyun/202509/18 BOJ G4 \353\246\254\353\252\250\354\273\250.md" diff --git "a/lkhyun/202509/18 BOJ G4 \353\246\254\353\252\250\354\273\250.md" "b/lkhyun/202509/18 BOJ G4 \353\246\254\353\252\250\354\273\250.md" new file mode 100644 index 00000000..52490d9a --- /dev/null +++ "b/lkhyun/202509/18 BOJ G4 \353\246\254\353\252\250\354\273\250.md" @@ -0,0 +1,56 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N, M; + static boolean[] broken = new boolean[10]; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + M = Integer.parseInt(br.readLine()); + if(M!=0){ + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < M; i++) { + broken[Integer.parseInt(st.nextToken())] = true; + } + } + + int result = Math.abs(N - 100); + + for (int channel = 0; channel <= 1000000; channel++) { + int cnt = getCount(channel); + if (cnt > 0) { + int total = cnt + Math.abs(N - channel); + result = Math.min(result, total); + } + } + + bw.write(result+""); + bw.close(); + } + + static int getCount(int channel) { + if (channel == 0) { + return broken[0] ? -1 : 1; + } + + int count = 0; + int temp = channel; + + while (temp > 0) { + int digit = temp % 10; + if (broken[digit]) { + return -1; + } + count++; + temp /= 10; + } + + return count; + } +} +```