devapriyanta's blog

By devapriyanta, history, 3 days ago, In English

281319592

I have given a solution is o(n*m*5) which should ideally be accepted, but giving TLE. Can anyone please help me the flaw in this code.

TIA.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

It might be due to the fact that the number of test case is less than equal to 10^5 and you have done memset(dp,-1,sizeof(dp)); in each iteration , ur size of dp is 1000 by 5 , therefore the worst case time complexity for your code would be 5 * 10^8 in a testcase , which might be why you are getting tle.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

281369677

have tried defining vector with size pertaining to each test case but still failing.

»
3 days ago, # |
  Vote: I like it 0 Vote: I do not like it

use INT_MIN or something like that, for initialize dp vector.