Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

shubhamphpefy's blog

By shubhamphpefy, history, 7 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

»
7 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.

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

    Yes! Understood. Thank you so much. I assumed that there will be always single instance of each character in 'IEHOVA' that's not the case actually.There is only one path but can have multiple occurrence of single character.

    Thank you so much for your time.