Блог пользователя lalalalaaa...

Автор lalalalaaa..., история, 6 лет назад, По-английски

I have started solving some problems related to graphs and most of the times i am not able to pass the testcases, either it is TLE or WA. I was solving MONSTERS question from cses Problem Link and was unable to figure to out why some testcases gave TLE.

What i have done-

Applied bfs and stored the min distance between each cell and the monster (M) cell. Applied bfs for A and check whether there was a cell which was having less distance/ or more closer to A than any other M cell. And then checked whether it can reach to any border cell.

Link to My Code

It will be very helpful if anyone can let me know where i am going wrong.

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

You can check this, I have used bfs
CODE_LINK

CODE
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Hint
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi there,

Sorry haven't thought about the exact error in your code but I will state why I was getting WA and TLE

The reason for TLE was the case when your character is already at a border cell and the reason for WA was due to >= instead of just > when comparing distance during bfs from your cell.

»
23 месяца назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is there any question exact same as Monsters cses om Codeforces