Editorial for Mock CCC '22 Contest 1 J3 - String Crossing Maximization
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
The first subtask rewarded brute force solutions that ran in cubic time.
The second subtask was meant to guide contestants to the full solution.
To solve the problem fully, we realize that only the frequency of each character is relevant.
Let
The number of string crossings is the sum of
We can then test all pairs of characters, as there are only
Note that
Time Complexity:
Comments