ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1353. Milliard Vasya's Function

If you have TL (with recursion)
Posted by Evgeny Shulgin 1 Mar 2015 13:05
Let your recursion function is "void dfs1(int k, int curr)", k is digit, curr is current S, then use it code:

    int start = 0;
    start = max(start, curr - 9 * (k - 1));

    int end = min(9, curr);
    if(k == 10) {
        end = min(1, end);
    }

    for(int i = start; i <= end; i++) {
        dfs1(k - 1, curr - i);
    }

It turns out, curr does not go beyond zero at k = 0!
I have 937ms with this solution

But with precalc I have 31ms :)
Good luck