Question about vector vs. array in a certain problem

Revision en1, by ycperson, 2024-09-09 20:02:44

I was doing this problem https://codeforces.net/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://codeforces.net/contest/1822/submission/280480288 My submission just before that (using static array a): https://codeforces.net/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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English ycperson 2024-09-09 20:04:32 0 (published)
en2 English ycperson 2024-09-09 20:04:14 3 Tiny change: '/280480288 \nMy submi' -> '/280480288\nMy submi' (saved to drafts)
en1 English ycperson 2024-09-09 20:02:44 887 Initial revision (published)