Editorial for Mock CCC '26 S2 - The Quick Brown Fox
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
We can directly simulate excluding each string individually. For each string, loop through all the other strings and check if all characters appear at least once.
Each of the strings we consider excluding, and we must loop through the remaining
strings with length
yielding a time complexity of
.
Subtask 2
As is now larger, we need to find a better way than looping all
characters when looking through a string.
Since we only care about whether or not a string contains a character, rather than the number of them, we can simply create a boolean array table for each character for each string. If we loop through each string, and each string mark down in the boolean table whether or not a character has been seen, later when looping through a string we can simply refer to the boolean table of only elements rather than looping through the string of length
. With this preprocessing, this yields a time complexity of
.
Full Solution
As is now larger, we need a faster way than simulating excluding each string.
Before excluding any string, first check if all the strings together are a pangram. If any character doesn't appear in any of the strings, we know there are ways to create a pangram with
less string.
Otherwise, we can observe that if a string were to be excluded and the remaining strings do not form a pangram, then there must be at least one character that exclusively shows up in that string. We can build a frequency table of size , indicating the number of strings that contain each character. Afterwards, we can loop through each string, and if we find a string that has a character that only appears in one string, then we know we must keep that string.
We can assume all strings could be excluded, then subtract off any ones we know must be kept, and that leaves us with our final answer. This yields a time complexity of
.
Alternative Solution
Alternatively, we can speed up the subtask solution by ordering the strings and maintaining a prefix and suffix frequency table of all characters seen. If we check if the
string can be excluded, the combined frequency tables of the first
strings and all strings after
shouldn't have any characters with no frequency. This yields the same time complexity as of
.
Comments