Editorial for BPC 1 J4 - Assignment of the Year
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Hint 1
This is a DP problem. You can use whether or not it is possible to produce
using the first
digits.
Hint 2
You only need to test numbers that are up to digits long. All numbers with
digits or more are guaranteed to be greater than
.
Solution
Starting from the left, apply the following process starting from each digit:
- If the
digit is
we can skip the next 3 steps and copy
into
.
- Use
digits, where
is
greater than the amount used in the previous iteration, and
on the first. Let
be the number made out of these digits.
- Stop if
.
- For all
, set
.
At the end of this process, you can count the number of values that you've created in .
Comments