Editorial for Another Contest 9 Problem 4 - Alchemy


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.

This problem is solvable with a few different approaches, using greedy strategies or some casework. The reference solution solves this recursively, keeping a state of how many digits have been accumulated, which digits have been used, and whether we have exceeded the given number or if the prefix exactly matches, greedily trying the smallest prefix. Some state pruning may be necessary.


Comments

There are no comments at the moment.