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

Автор Sunk_Cost, история, 3 года назад, По-английски

I have tried different times in different ways to execute an accepted solution but Alas, everytime I failed. I would be eternally grateful if someone could debug my code and say what and where I should change in my code so that I won't get TLE. Here is my code Geting TLE in 1000 x 1000 grids Thanks a lot in advance.

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

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

Have you thought about what the time complexity is of your approach? I see you are running a lot of BFS's in a loop. Ok, that seems to be alright, because there's only one character in the grid that's A. Another concern is the many maps you are using for storing info. They give an extra log factor, with quite a big constant. Try changing them to arrays.

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

Hey your approach seems correct its just multisource bfs, I see you are using a lot of maps, avoid using them cses is quite strict on time limit instead use 2d arrays wherever possible instead of maps.

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

Thanks, I got stuck on the same.