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

Автор bobbilyking, история, 6 лет назад, По-английски

https://pastebin.com/zV3jsqy7

i did look at the CF editorial, and yeah my implementation (i don't think) is wrong. and someone else had the same TLE problem as me but he never said how he resolved it (if he ever did). Is this just a java thing? Editorial says that time complexity is n * target, which is 10^8 operations, so maybe I can make very very slight optimizations somewhere to get it under 1ms?

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

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

I also got TLE with recursive dp in c++ and had to do iterative. Timelimit is strict but 10^8 is indeed the intended complexity. Try swapping out the modding line with this as mod is a heavy operation.

if (whatever >= MOD) whatever -= MOD

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

Not sure in java but in C++ a%b works slightly faster if b is a constant. So in the following code int mod = 1e9 + 7 will give TLE but int const mod = 1e9 + 7 will not.

dp[0] = 1;
    for (int i = 1; i <= m; i++)
    {   for (int j = 1; j<= n; j++)
        {   int x = i - a[j];
            if (x >= 0)
                dp[i] = (dp[i] + dp[x])%mod;
        }
    }
    cout << dp[m];
  • »
    »
    4 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    This saved me in other problem, I was getting TLE with almost the same code I done 2 years before. just adding a const and it got accepted.

    In Problem "Graph paths I" runs 4 times faster, about 57 million of '%' operations in the worst test case.

»
3 года назад, скрыть # |
Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

[deleted comment]