Akshito's blog

By Akshito, history, 11 years ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
11 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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.