Editorial for WC '15 Contest 3 S2 - Detective Work


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 problem of trying to make all of the strings equal can be reduced to the problem of making each column of the row of strings equal. So every index (from 1 to M) can be handled independently, and we are simply trying to transform that index across all N strings to the same letter. For each index, we need to find two values – the minimum number of letter replacements in the column to make that index equal across all N strings, and the number of ways to do so.

For a given index, we should consider each possible letter (from A to Z) to transform the entire column to. The cost to transform the column into a given letter is the number of strings which have a non-wildcard letter at the current index which is different than the chosen letter. The minimum cost for the index will then be the minimum of these costs over all 26 possible letters, while the count (error) will be the number of different letters from A to Z which have this minimal cost.

Now that we know how to get the costs and errors for each column, getting an overall answer is easy. The total cost will be the sum of these costs, since to change all of the strings, we can simply change letters in all of the columns independently. From principles of basic combinatorics, we know that the total number of ways for M independent events to happen is just the product of the number of ways for each event to happen. So, to get the total error (number of possible words), we just multiply the number of possible ways for each index and modulo it by 1000.


Comments

There are no comments at the moment.