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

Автор hackerbhaiya, история, 4 года назад, По-английски

Yesterday, I was trying a problem. I got two different verdict on the apporx same code.
Solution 1 (Accepted) : https://codeforces.me/contest/271/submission/115150455
Solution 2 (Runtime Error) : https://codeforces.me/contest/271/submission/115150580

See line 83 of solution 1. There i have assigned pre[1][2] to some value which is out of bound. But still the code was accepted, it should give Runtime Error as given in the solution 2. In solution 2, I changed long long to int. I submitted another code in which i removed pre[1][2] assignment and then it was accepted.
Solution 3 : https://codeforces.me/contest/271/submission/115150618

Someone please tell why didn't I get RTE in my solution 1 as pre[1][2] is clearly out of bound?
Thanks in advance!

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

»
4 года назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

You very lucky. You overwrote some random value in memory, some random variable that is unused or was overwritten later or maybe you wrote a value to padding. Either way you didn't corrupt any data by coincidence.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    But why it gave RTE in solution 2? Everything is same as in solution 1, i just changed long long to int in solution 2.

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      Well, int takes 4 bytes in memory, long long takes 8 bytes in memory. So vector<int>(2) allocates (at least in theory) 8 bytes and vector<long long>(2) allocates 16 bytes, so maybe they used different allocation buckets. Or maybe the size was padded to 16 bytes so there were 8 bytes of unused padding in int case and no padding in long long case.