From 54540de2b1e50a79116e65de6dd7bff01912f2c2 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sat, 23 Aug 2025 11:31:21 +0900 Subject: [PATCH] =?UTF-8?q?[20250823]=20BOJ=20/=20G4=20/=20=EB=A6=AC?= =?UTF-8?q?=EB=AA=A8=EC=BB=A8=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 --- ...4 \353\246\254\353\252\250\354\273\250.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" diff --git "a/Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" "b/Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" new file mode 100644 index 00000000..49fcdd64 --- /dev/null +++ "b/Ukj0ng/202508/23 BOJ G4 \353\246\254\353\252\250\354\273\250.md" @@ -0,0 +1,69 @@ +``` +import java.io.*; +import java.util.*; + +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 boolean[] used; + private static int N, M, answer; + + public static void main(String[] args) throws IOException { + init(); + + for (int i = 0; i <= 1000000; i++) { + if (canPush(i)) { + int n = Math.abs(N - i) + length(i); + answer = Math.min(answer, n); + } + } + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + M = Integer.parseInt(br.readLine()); + answer = Math.abs(N - 100); + + used = new boolean[10]; + Arrays.fill(used, true); + + if (M > 0) { + StringTokenizer st = new StringTokenizer(br.readLine()); + + for (int i = 0; i < M; i++) { + int n = Integer.parseInt(st.nextToken()); + used[n] = false; + } + } + } + + private static boolean canPush(int num) { + if (num == 0) return used[num]; + + while (num > 0) { + int n = num % 10; + if (!used[n]) return false; + num /= 10; + } + + return true; + } + + private static int length(int num) { + if (num == 0) return 1; + + int count = 0; + while (num > 0) { + count++; + num /= 10; + } + + return count; + } +} +```