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

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

cannot figure out why TLE on http://codeforces.me/contest/330/problem/D

I have tried everything (but switch to C++)

here is code: http://codeforces.me/contest/330/submission/11660881

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

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

Try marking squares as visited when you insert them into the queue rather than when you take them out — I think the way you're doing it now results in a lot of duplicate entries and an exponential runtime. Alternately when processing a square you could check if you've already marked it as visited and if so don't process it again.