Блог пользователя simp_pro

Автор simp_pro, история, 5 месяцев назад, По-английски

What is the memory limit of my code : https://codeforces.com/contest/1706/submission/237628836

vector a,r : 2*8MB = 16MB

In vector<vector> change, I am pushing a new element only if a previous element is removed. It ensures that number of integers inside this change 2d vector is exactly n at all times. So it should be 8MB(for integers) + 8MB(for each vector)

Overall, it should be 32 MB only. However, it is exceeding 64 MB and giving help

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by simp_pro (previous revision, new revision, compare).

»
5 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

std::vector doesn't free the allocated space when calling pop_back(): https://stackoverflow.com/questions/1536753/does-stdvector-pop-back-change-vectors-capacity

You can reduce capacity with vector::shrink_to_fit(), but that is $$$O(\mathrm{size})$$$ which isn't fast enough (237641351).

Instead, you can use a linked list (std::list). It is significantly slower than std::vector here, but it's still fast enough (237641788).