Why TLE?

Правка en3, от _14_, 2024-08-17 05:16:47

In the last educational round, my below solution for the problem 2004D - Colored Portals got TLE.

TLE solution: 276676175

After the contest, I submitted the solution with only one line of change in code and it got AC.

AC solution: 276725505

The only difference between both the codes is:

In the TLE solution:

for (auto x : mp)

And in the AC solution:

for (auto x = mp.begin(); x != mp.end(); x++)

Anyone, please help me to find out the time complexity of each statement. And why this first one gives TLE?

Which statement should be preferred to avoid this type of situation?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский _14_ 2024-08-17 05:19:00 0 (published)
en3 Английский _14_ 2024-08-17 05:16:47 74
en2 Английский _14_ 2024-08-17 05:14:04 14
en1 Английский _14_ 2024-08-17 05:11:30 585 Initial revision (saved to drafts)