Блог пользователя ASHWANTH_K

Автор ASHWANTH_K, история, 5 месяцев назад, По-английски

https://cses.fi/problemset/task/2174
i am clueless for this problem. please help me .
I have solved the easy verison of problem using O(N) dp.
I have spent a good amount of time thinking but could not find any solution.

It would be nice if i get any hints.. instead of actual solution...

I have given thoughts about matrix exponentiation, or any observation patterns ... nothing seems to workout.

  • Проголосовать: нравится
  • +31
  • Проголосовать: не нравится

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to solve this kind of adhoc problems actually...

»
4 месяца назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Auto comment: topic has been updated by ASHWANTH_K (previous revision, new revision, compare).

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Did you try greedy?

»
4 месяца назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Notice that you always take the biggest digit to subtract.

Now the remaining problem is to quickly simulate it.

You will encounter a lot of 9s in form of ABCD999999E.

If we know how to solve D999999E, in maybe O(1), (with the maximum digit before it being some F), then we can reduce it to ABC9999999?, which is easier.

For answers of digit in form ????A99999B (with C as the max digit before A), we always reduce 9 until it become A90000B, then we will have A8999?, which is a smaller subproblem — see the DP here?

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can't you just go greedy and subtract the largest digit that there is currently.

  • »
    »
    4 месяца назад, # ^ |
    Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

    let's say you manage to subtract $$$9$$$ in every iteration, and let's say you get the largest digit in $$$O(1)$$$, your idea is still $$$O(\frac{n}{9})$$$, and $$$n\le 10^{18}$$$ :)