Skip to content

Commit 55c488a

Browse files
authored
Merge pull request #1101 from AlgorithmWithGod/LiiNi-coder
[20251012] BOJ / G4 / 리모콘 / 이인희
2 parents 582f688 + 07575ad commit 55c488a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static boolean[] Broken = new boolean[10];
7+
private static int Target;
8+
private static int M;
9+
private static List<Integer> availableButtons = new ArrayList<>();
10+
11+
public static void main(String[] args) throws IOException {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
Target = Integer.parseInt(br.readLine());
14+
M = Integer.parseInt(br.readLine());
15+
16+
if(M > 0){
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
for (int i = 0; i < M; i++) {
19+
int b = Integer.parseInt(st.nextToken());
20+
Broken[b] = true;
21+
}
22+
}
23+
24+
for(int i = 0; i <= 9; i++) {
25+
if (!Broken[i]) availableButtons.add(i);
26+
}
27+
int minPress = Math.abs(Target - 100);
28+
for(int num = 0; num <= 999999; num++){
29+
if (canMake(num)) {
30+
int pressCount = String.valueOf(num).length() + Math.abs(num - Target);
31+
//System.out.println(pressCount);
32+
minPress = Math.min(minPress, pressCount);
33+
}
34+
}
35+
System.out.println(minPress);
36+
br.close();
37+
}
38+
39+
private static boolean canMake(int num) {
40+
if(num == 0)
41+
return !Broken[0];
42+
while(num > 0){
43+
if (Broken[num%10])
44+
return false;
45+
num /= 10;
46+
}
47+
return true;
48+
}
49+
}
50+
51+
```

0 commit comments

Comments
 (0)