tarkus's blog

By tarkus, history, 5 years ago, In English

Hello guys, yesterday i was trying to solve this problem 20C - Алгоритм Дейкстры? but i'm getting runtime error with this test case: 50906466

Debugging i found out my program is crashing when is reading "w" in the for loop, but i can't understand why.

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

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Just did a quick look through your code, and I noticed an error. You might get overflow because nmaxwmax = 1011 which doesn't fit in an int. But the error crashing your code is something different.

»
5 years ago, # |
Rev. 5   Vote: I like it +1 Vote: I do not like it

The following is a very slight accepted fix 51069859 of your code with the following notes:

  1. Reversing the 'ans' string is valid only when the string representation of the node is a palindrome string. For example, reversing 'ans' when one of the vertices of the optimal path is 24 will produce 42 (which is wrong answer) as "24" is not a palindrome string. The simple fix is to use a stack, vector, deque, etc. for storing the vertices, and printing the number in reversed order.

  2. The total distance of the optimal path exceeds INT_MAX for some test cases. Hence, the data type for storing the optimal distance should be upgraded to 64-bit.

  3. The constant used for INF was not large enough for some test cases. Setting such value to 1014 was sufficient to pass the system tests.

The following is another accepted solution with further update to your code 51072220.