Official

G - Count Strictly Increasing Sequences Editorial by en_translator


Let \(\mathrm{dp}_{i,j,k}\) be “the number of ways to determine the \((k+1)\)-th and later digits of \(S_i,S_{i+1},\ldots,S_{j-1}\) such that \(S_i \lt S_{i+1} \lt \ldots \lt S_{j-1}\) within those digits.” (DP stands for Dynamic Programming.) Here, within the specified segment, the \((k+1)\)-th digits are weakly increasing; additionally, within a segment with the same \((k+1)\)-th digits, the \((k+2)\)-th and later digits must form weakly increasing integers. Thus, the DP can be evaluated by considering the ways to split \(S_i,S_{i+1},\ldots,S_{j-1}\) into segments where the \((k+1)\)-th segments are 0, 1, \(\ldots\), and 9. Specifically, we evaluate \(\mathrm{dp}_{i,j,k,l} =\) “the number of ways to determine the \((k+1)\)-th and later digits of \(S_i \lt S_{i+1} \lt \ldots \lt S_{j-1}\) such that \(S_i \lt S_{i+1} \lt \ldots \lt S_{j-1}\) within those digits and zero or more first \((k+1)\)-th digits are \(l\),” which can be evaluated in a total of \(\mathrm{O}(N^3Mb)\) time (where \(b\) is the number of kinds of digits).

posted:
last update: