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

Автор rahulnagurtha, история, 8 лет назад, По-английски

While I was solving this question during virtual contest, this submission gave me Memory Limit Exceeded verdict, when I changed the code slightly (I just made "vector" ans a global vector) it was accepted, here is the accepted version. The point to observe here is that "vector ans" is of size 193 only, which is very small to cross the given memory limits. I couldn't figure out what is wrong with my code. Any help is appreciated.

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

»
8 лет назад, # |
Rev. 2   Проголосовать: нравится +27 Проголосовать: не нравится

The last element of your "primes" will be 997 and beyond this, it contains undefined values (technically, it is an undefined behaviour and one cannot even assume that it contains something). If the undefined value at the end of "primes" have some property (e.g. zero, one, or some negative values (overflow can complicates the thing)), "tmp" never exceeds "n" and it will loop forever. Thus it will push_back repeatedly and will eventually be MLE.