Skip to content

Commit ea4f035

Browse files
authored
Merge pull request #764 from AlgorithmWithGod/0224LJH
[20250828] BOJ / G2 / 성냥개비 / 이종환
2 parents 1f1e29c + 3f327ba commit ea4f035

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
```java
2+
import java.io.IOException;
3+
import java.math.BigInteger;
4+
import java.io.*;
5+
import java.util.*;
6+
7+
8+
public class Main {
9+
10+
// 1-> 2개 | 2 -> 5개 | 3 -> 5개 | 4개 -> 4개 | 5 -> 5개 |
11+
// 6-> 6개 | 7 -> 3개 | 8 -> 7개 | 9개 -> 6개 | 0 -> 6개 |
12+
13+
static int[] costs = {6 , 2, 5, 5, 4, 5, 6, 3, 7, 6, 6};
14+
static BigInteger[] max, min;
15+
16+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
17+
static int cnt = 0;
18+
static final int LARGER = 1;
19+
static final int SMALLER = -1;
20+
21+
public static void main(String[] args) throws IOException {
22+
int TC = Integer.parseInt(br.readLine());
23+
24+
for (int tc = 1; tc <= TC; tc++) {
25+
init();
26+
process();
27+
print();
28+
}
29+
}
30+
31+
public static void init() throws IOException {
32+
cnt = Integer.parseInt(br.readLine());
33+
max = new BigInteger[cnt+1];
34+
min = new BigInteger[cnt+1];
35+
36+
for (int i = 0; i <= cnt; i++) max[i] = BigInteger.ZERO;
37+
min[0] = BigInteger.ZERO;
38+
}
39+
40+
public static void process() throws IOException {
41+
for (int i = 0; i < cnt; i++) {
42+
BigInteger lNum = max[i];
43+
BigInteger sNum = min[i];
44+
45+
46+
int left = cnt - i;
47+
for (int j = 0; j < 10; j++) {
48+
if (left < costs[j]) continue;
49+
50+
BigInteger plus = BigInteger.valueOf(j);
51+
BigInteger nLNum = lNum.multiply(BigInteger.valueOf(10)).add(plus);
52+
53+
54+
if ( nLNum.compareTo( max[i+costs[j]]) == LARGER) max[i+costs[j]] = nLNum;
55+
}
56+
57+
if (sNum == null) continue;
58+
59+
60+
for (int j = 0; j < 10; j++) {
61+
62+
63+
if (sNum == BigInteger.ZERO && j == 0) continue;
64+
if (left < costs[j]) continue;
65+
66+
BigInteger plus = BigInteger.valueOf(j);
67+
BigInteger nSNum = sNum.multiply(BigInteger.valueOf(10)).add(plus);
68+
69+
if (min[i+costs[j]] == null
70+
|| nSNum.compareTo(min[i+costs[j]]) == SMALLER) min[i+costs[j]] = nSNum;
71+
72+
}
73+
}
74+
75+
}
76+
77+
78+
79+
public static void print() {
80+
System.out.println(min[cnt].toString() + " " + max[cnt].toString());
81+
}
82+
}
83+
84+
```

0 commit comments

Comments
 (0)