Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

shubhamphpefy's blog

By shubhamphpefy, history, 13 months ago, In English

Hey there! Actually I tried to solve this problem on UVA. I submitted this solution on vjudge but it is giving TLE. On local machine it is working for all test cases that I tried. I tried to debug as well initially. Now that I am getting correct answers but TLE as well I don't know what's going wrong. Please Help.

P.S. : This is my first blog entry.

Tags uva, dfs
  • Vote: I like it
  • +10
  • Vote: I do not like it

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

Consider this case:

1
4 5
XXX#X
XIXIX
XIIIX
X@XXX

You are greedily taking the first option that will let you move one square, but this means that you will get stuck on row 2, column 2. Due to the way your code is written (you will make no movement if you have no options, but won't break out of the loop either) this results in an infinite loop.