Editorial for Mock CCC '26 S2 - The Quick Brown Fox


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.

Author: AndyMan68

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 S strings we consider excluding, and we must loop through the remaining S-1 strings with length L yielding a time complexity of \mathcal{O}(S^2 \times L).

Subtask 2

As L is now larger, we need to find a better way than looping all L 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 26 elements rather than looping through the string of length L. With this preprocessing, this yields a time complexity of \mathcal{O}(S^2 + S \times L).

Full Solution

As S 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 0 ways to create a pangram with 1 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 26, 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 S 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 \mathcal{O}(S \times L).

Alternative Solution

Alternatively, we can speed up the subtask 2 solution by ordering the strings and maintaining a prefix and suffix frequency table of all characters seen. If we check if the i^\text{th} string can be excluded, the combined frequency tables of the first i-1 strings and all strings after i shouldn't have any characters with no frequency. This yields the same time complexity as of \mathcal{O}(S \times L).


Comments

There are no comments at the moment.