Editorial for WC '18 Contest 1 S2 - Essay Generator


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.

The essay should include as many distinct length-1 words as possible (of which there are 26). If Alice runs out of those, then the essay should be filled in with as many distinct length-2 words as possible (of which there are 26^2 = 676). If Alice also runs out of those, then she should pad out the remainder with length-3 words. She'll never need to resort to length-4 words, as the total number of words with lengths 1 \dots 3 is 26+26^2+26^3 = 18\,278, which is greater than the maximum value of W (10\,000).

With that in mind, there are various possible ways to generate an optimal essay in \mathcal O(W) time. We might consider each length L from 1 to 3 in turn, and generate all words of length L in any order (either with recursion or with L nested loops), appending them to the essay and stopping early if the essay's length reaches W. It's also possible to get it done with just three nested loops representing the word's first, second, and third characters, with the first two loops including placeholder values which represent words with shorter lengths.


Comments

There are no comments at the moment.