Editorial for Riolku's Mock CCC S2 - Keen Keener Sequence
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
For this subtask, we can brute force all -tuples. Make sure that all indices used are distinct for each tuple.
Time Complexity:
Subtask 2
For this subtask, we can brute force the first three elements of the tuple. We can compute , and find out how many times shows up in the array. We need to subtract for each of or or .
Time Complexity:
Subtask 3
For this subtask, we can loop through the first two elements of the tuple. We can store how many times the product appears.
Then, we can loop through the first two elements again. We can add to the total the number of times shows up across all other pairs.
Unfortunately, we might over-count any pairs or , so we can use a frequency array to exclude those.
Also, we have removed the pair too many times, so we should add back to our total.
Finally, we also have to add back pairs if , since then the pairs and are excluded too many times.
Time Complexity:
Note: Although the complexity of this problem is , most solutions use a map and perform very poorly. A harder version of this problem exists to challenge those who are interested. Hint: don't use a map.
Comments