ThandePaji's blog

By ThandePaji, history, 6 weeks ago, In English

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

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

»
6 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    6 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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

    • »
      »
      »
      6 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

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

      • »
        »
        »
        »
        6 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 !

        • »
          »
          »
          »
          »
          6 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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.

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      OK, updated the comment above.