Weird TLE for Vector not for Map Seriously!!!! Help

Правка en1, от Revenir_03, 2023-01-10 19:15:08

In the Contest Codeforces Round #843 (Div. 2) Problem B. Gardener and the Array I got TLE for the Code in Which I used a Vector of size 200007 vector p(200007, 0); and after contest I tried Submitting the same solution using Map in place of vector map<int, int>p; and the solution got accepted, The Time Complexity of Both the codes is O(N). Seriously Vector takes less time than map and I don't know why and how can a Map beat Vector in TC. If anyone know the reason behind this please explain. Thank you for your time.

Both the submissions 1) Using Vector: 188741557 2) Using Map: 188778187

After Seeing Solution of Map getting Accepted I was quite enraged, as in some contests for some problem I got TLE because of using Map instead of Vector and This time I didn't think of Map and it satisfied the TC. Please explain the reason behind this and when should we use map and vector when both data structures can be used.

Теги time limit exceeded, maps, vector, contest, time complexity, codeforces round 843, gnu c++17, time, testing, testing system

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Revenir_03 2023-01-10 19:41:09 177
en1 Английский Revenir_03 2023-01-10 19:15:08 1108 Initial revision (published)