anipnwr's blog

By anipnwr, history, 4 years ago, In English

Hi!

I was trying the Atcoder educational DP contest and I wrote a recursive DP solution for problem A . It works fine for 7 test cases but fails for last 4.

The point that is disturbing me is that, similar logic but iterative code of DP is getting accepted for other people.

Can someone please help me with this or point out my mistake if I am doing a foolish one.

This is my code

This is the iterative code that works

ALSO, ONE MORE DOUBT. I DOWNLOADED THE TEST CASE, IT HAD SOME 99000 VALUES IN ARRAY. THE CODE JUST DIDN'T GIVE ANY OUTPUT IN SUBLIME TEXT. I TRIED SOME ONLINE COMPILERS THEY ALSO HAD A INPUT SIZE RESTRICTION. SO IT ALSO DIDN'T WORK. MY QUESTION IS, IS IT SOME RESTRICTION THAT WINDOWS OS HAS INBUILT OR IT IS SOME OTHER ISSUE?

Thanks in advance.

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

| Write comment?
»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

in function cal, you are checking only for (abs(v[n] - v[n - 1]) < (abs(v[n] - v[n - 2])), but it is not always true. It is possible that (abs(v[n] - v[n - 1]) < (abs(v[n] - v[n - 2])), but cal(n - 1) is much bigger than cal(n - 2). So, it should be (abs(v[n] - v[n - 1]) + cal(n - 1) < (abs(v[n] - v[n - 2]) + cal(n - 2))

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

For the sublime text, I sometimes had it not output anything to the file when in reality there was a runtime error. Maybe consider switching to Visual Studio as it has better debugging capabilities without much setup.