#P8535. Maximal Chinese Digit
Maximal Chinese Digit
Maximal Chinese Digit
You are given a special seven‐row dot matrix pattern for the Chinese digits 0 through 9 where each digit is drawn on a 7×7 grid (with width 7 and unlimited length to display multiple digits). The only characters used are .
and *
. The cost to display a digit is defined as the total number of *
characters in its pattern. The patterns (provided separately as text) have the following costs:
- 0: 5
- 1: 8
- 2: 15
- 3: 30
- 4: 23
- 5: 11
- 6: 16
- 7: 10
- 8: 18
- 9: 24
You are given an integer n which denotes the maximum number of available *
characters. Using at most n stars (you do not have to use all of them), construct the largest possible integer by concatenating Chinese digits. Note: When forming the number, ignore any place‐value units (such as thousand, hundred, etc.).
Hint (in LaTeX): If we denote the cost for digit d by \(c_d\), then the minimum cost available is \(\min\{c_d\}\). However, to avoid a leading zero (unless the number is zero), the first digit must be chosen from \(\{1,2,\dots,9\}\) with the least cost \(\min\{c_d: d\ge1\}\). Then, if you let L be the maximum number of digits you can draw, you have \[ L=1+\left\lfloor\frac{n-c_{min(nonzero)}}{\min\{c_d\}}\right\rfloor. \] After initializing the number with the minimum cost digits, you can greedily try to upgrade each digit (from left to right) to a higher value if the extra cost fits in the remaining budget.
inputFormat
The input consists of a single integer n
(\(5 \le n \le 10^9\)), representing the maximum number of available *
characters. Note that if n
is less than the minimum nonzero digit cost (which is 8), then only the digit 0 can be displayed.
outputFormat
Output the largest possible integer (as an ordinary integer without leading zeros) that can be drawn using at most n
*
characters.
sample
5
0