Skip to content

Commit 646fdbd

Browse files
authored
Merge pull request #647 from AlgorithmWithGod/JHLEE325
[20250811] BOJ / G4 / 리모컨 / 이준희
2 parents b25bad7 + aeb887a commit 646fdbd

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
```java
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
static boolean[] broken = new boolean[10];
9+
10+
public static void main(String[] args) throws Exception {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
13+
int n = Integer.parseInt(br.readLine().trim());
14+
int m = Integer.parseInt(br.readLine().trim());
15+
16+
if (m > 0) {
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
for (int i = 0; i < m; i++) {
19+
broken[Integer.parseInt(st.nextToken())] = true;
20+
}
21+
}
22+
23+
int answer = Math.abs(n - 100);
24+
25+
for (int ch = 0; ch <= 1000000; ch++) {
26+
int len = canpress(ch);
27+
if (len == -1) continue;
28+
int press = len + Math.abs(n - ch);
29+
if (press < answer) answer = press;
30+
}
31+
32+
System.out.println(answer);
33+
}
34+
35+
static int canpress(int ch) {
36+
if (ch == 0) return broken[0] ? -1 : 1;
37+
int len = 0;
38+
while (ch > 0) {
39+
int d = ch % 10;
40+
if (broken[d]) return -1;
41+
len++;
42+
ch /= 10;
43+
}
44+
return len;
45+
}
46+
}
47+
48+
```

0 commit comments

Comments
 (0)