BanazadehAria's blog

By BanazadehAria, history, 15 months ago, In English

Hi I wrote top-down dp for this problem but my code gets TLE for test case 6 I must change it to bottom-up or there is a trick to don't get TLE?

My code ==> https://codeforces.com/contest/366/submission/56265597

Problem Link ==> https://codeforces.com/contest/366/problem/C

Any type of help is appreciated. Thanks in advance.

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

You don't need this map<int,map<int,int> >, I think this is your problem. Take a look to my code and if you have any question tell me :)

My code

Btw, I used map in this and got TLE, that why i changed it.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you :(

    if( use[pos][dif+100000] ) return DP[pos][dif+100000]; use[pos][dif+100000] = true;

    Why did you do this i think it will work if its negative but it will change if the number is positive no?

    • »
      »
      »
      15 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes, but i'm used to code this way XD

      • »
        »
        »
        »
        15 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I think it's necessary here because maybe the difference gets negative.

        • »
          »
          »
          »
          »
          15 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          diff < 0

          so you used map to store a[diff] -> TLE

          he used aray a[diff + 1e5] -> AC