Question about vector vs. array in a certain problem

Правка en2, от ycperson, 2024-09-09 20:04:14

I was doing this problem https://mirror.codeforces.com/contest/1822/problem/G1 recently, and I was comparing my code to the editorial implementation and I kept getting TLE again and again, trying to make the code more and more similar to the implementation given. The ultimate thing that allowed AC was changing the static array "a" to a vector of size n as in the implementation. Anyone know why the vector performs better? Because I thought static arrays were faster if anything.

My AC submission: https://mirror.codeforces.com/contest/1822/submission/280480288

My submission just before that (using static array a): https://mirror.codeforces.com/contest/1822/submission/280480106

(Just scroll down to the main function at the very bottom -- there is a bunch of template stuff above it not for the problem).

Thank you in advance for any help.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский ycperson 2024-09-09 20:04:32 0 (published)
en2 Английский ycperson 2024-09-09 20:04:14 3 Tiny change: '/280480288 \nMy submi' -> '/280480288\nMy submi' (saved to drafts)
en1 Английский ycperson 2024-09-09 20:02:44 887 Initial revision (published)