Editorial for Mock CCC 25 S4 - Perfect Numbers
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.
Author:
There are two main observations needed for this problem. First, a number is "perfect" if it contains either one of two cases:
\(2\) consecutive digits that are equal
\(3\) consecutive digits that are all different
If either of these conditions are true, a number will always be perfect.
Subtask 1 [3/15]
This subtask rewards brute force solutions.
Time Complexity: \(O(R-L+1)\).
Subtask 2 [12/15]
Since we only need to keep track of \(3\) digits at a time, this problem can be solved using digit dp.
Time Complexity: \(O(log(R-L+1))\)
Comments