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

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

I have been solving this problem https://codeforces.com/contest/339/submission/129086329 but while on test case 7(a very long test case) , I get this error saying 'the solution is executed with error out of bounds or other memory error' on line 18'. Codeforces is new for me, so could you tell me what is wrong with my code and how should I fix it? It would mean a lot.

Thanks

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

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

You have never assigned value to A so its length equals to zero. That's why you have out of bounds error,

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

    I did initialize A, in line10. Please elaborate..or if you could write the exact line of code required then it would be easier for me to understand. Thanks

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

      Add this line: A.resize(s.length()); before accessing your variable A.

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

        Thanks a lot @UpAndDown. My problem is fixed now :)

        Though I don't want to bother you anymore but if you could tell me why this only happened with bigger test cases and what topic should I learn so that this doesn't happen again.

        Thanks again !

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

          Learn what's index out of bounds exception, don't forget to assign any value to a variable anymore. If you want to assign a default value to it ("" — for strings, 0 — for ints and so on) do this explicitly.

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

      OK, updated the comment above.