Editorial for WC '16 Finals J2 - Enigmoo


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.

Overall, we want to iterate over each of the N words, and determine whether or not it can correspond to the encrypted message. If so, then we can increment a running total of possible words, which we'll output at the end.

To determine whether or not a given word i is valid, we need to consider each possible value of S between 1 and 25 (remembering to exclude 0), and check if at least one such value would result in the encrypted word matching W. If multiple S values would work (which is the case when W is made up entirely of ? characters), we need to make sure to still only count the word once!

Finally, determining whether a given value of S makes a certain word D_i valid involves checking whether all N of its characters are independently valid. For each index j from 1 to N, we need to compute the value of D_{i,j} when it's cyclically shifted forward in the alphabet by S spots, and check whether that value is equal to W_j. However, if W_j is equal to ?, then index j should instead be skipped, as any original character at that index would be valid.


Comments

There are no comments at the moment.