跳到正文

题解

[AGC011E] Increasing Numbers Tutorial

MatrixGroup约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
获赞
2

版本

  1. v1当前

Apply binary search on the answer, one only needs to check whether NN can be represented as the sum of MM increasing numbers. The key observation is that a number is increasing if and only if it can be represented as the sum of exactly 99 repunits, where a repunit is a number in the form 00 or 11⋯111\cdots1. Therefore, one only needs to check whether NN can be represented as the sum of 9M9M repunits. Since all repunits has the form of 10K−19\dfrac{10^K-1}{9}, the condition holds if and only if 9N9N can be represented as the sum of 9M9M numbers of the form 10K−110^K-1, which is equivalent to whether the digit sum of 9N+9M9N+9M is no more than 9M9M. This can be easily checked. With a trivial greedy algorithm which decreases the number by the maximum possible repdigit, one can easily show that the answer has an upper bound of O(log⁡N)O(\log N). Therefore, the problem can be solved in the time complexity of O(log⁡Nlog⁡log⁡N)O(\log N\log \log N).

原文