At first, let’s simplify the problem a little bit. If we know the answer ARA_R for [1,R][1, R] range and the answer AL1A_{L-1} for [1,L1][1, L-1] range, we can calculate the answer for [L,R][L,R] range by subtracting AL1A_{L-1} from ARA_R.

Now, let’s simulate the process of building the numbers. Let’s say, currently, the number is yy01xxxyy01xxx, where yy are the digits we have placed already and xx are the digits we need to place. Now, if we can compute the count of the numbers we can build by placing the digits in the positions of xx, we can easily calculate the contribution of 0101 in this position of the numbers having a structure like this.

To calculate this, we can apply digit Dynamic Programming approach. Definition like this f(isStart,isSmall,pos,prv)f(isStart, isSmall, pos, prv) is enough to define the DP state while building the numbers. Here, isStartisStart is a flag indicating if the current position is the first position of the number; isSmallisSmall indicates if the number we are building is smaller than RR; pospos is the current position we are placing digit and prvprv is the value we have placed in the previous position. To get the count of numbers and the amount of rhodium from a state together, we may need to manage two DP arrays. An array of pairs also suffices.

Setter’s solution: https://ideone.com/Z5KAJ8

Statistics

75% Solution Ratio
YouKnowWhoEarliest, Dec '21
Kuddus.6068Fastest, 0.4s
nusuBotLightest, 4.9 MB
tanzim_bnShortest, 873B
Toph uses cookies. By continuing you agree to our Cookie Policy.