Skip to content

Commit 54540de

Browse files
authored
[20250823] BOJ / G4 / 리모컨 / 한종욱
1 parent a9205ac commit 54540de

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static boolean[] used;
9+
private static int N, M, answer;
10+
11+
public static void main(String[] args) throws IOException {
12+
init();
13+
14+
for (int i = 0; i <= 1000000; i++) {
15+
if (canPush(i)) {
16+
int n = Math.abs(N - i) + length(i);
17+
answer = Math.min(answer, n);
18+
}
19+
}
20+
21+
bw.write(answer + "\n");
22+
bw.flush();
23+
bw.close();
24+
br.close();
25+
}
26+
27+
private static void init() throws IOException {
28+
N = Integer.parseInt(br.readLine());
29+
M = Integer.parseInt(br.readLine());
30+
answer = Math.abs(N - 100);
31+
32+
used = new boolean[10];
33+
Arrays.fill(used, true);
34+
35+
if (M > 0) {
36+
StringTokenizer st = new StringTokenizer(br.readLine());
37+
38+
for (int i = 0; i < M; i++) {
39+
int n = Integer.parseInt(st.nextToken());
40+
used[n] = false;
41+
}
42+
}
43+
}
44+
45+
private static boolean canPush(int num) {
46+
if (num == 0) return used[num];
47+
48+
while (num > 0) {
49+
int n = num % 10;
50+
if (!used[n]) return false;
51+
num /= 10;
52+
}
53+
54+
return true;
55+
}
56+
57+
private static int length(int num) {
58+
if (num == 0) return 1;
59+
60+
int count = 0;
61+
while (num > 0) {
62+
count++;
63+
num /= 10;
64+
}
65+
66+
return count;
67+
}
68+
}
69+
```

0 commit comments

Comments
 (0)