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

Автор hrushikesht, 7 лет назад, По-английски

I submitted a solution to Captain Marmot 474C. I am getting "Runtime Error" which says "Exit code is 3". I am getting the error for test case 1 for which the program is printing the answer correctly, as this is the sample test case. I am also returning 0 at the end of the code.

Here's the submission link. 27468903

Code

I am unable to find the problem in my code. Any kind of help in this issue is appreciated. Thanks in advance.

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

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

interestingly, resubmitting the exact same code get you to runtime error on test 6. 27469444. I suspect the fault is on the judge and not your code for your first submission. Furthermore, changing vector to array gets WA on test 9. 27469694 I think I will leave the rest of the debugging to you

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

    Thanks for the debugging. Is there any difference when we use vectors instead of arrays?

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

      actually that is not the problem. I don't actually know where the problem lies, but I remember getting the same problem once when I keep clearing vector. That's why I change that.

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

I added the following code into your rotate function

if(i < 0 || i > 4){
    while(true){};
}

And got tle on test 1. So you are accessing mole[x] where x < 0 or x > 4, it's undefined behaviour.

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

I encountered this error here : ( n & 1 ) ? cout << string( n / 2 - 1 , 'a' ) : cout << string( n / 2 , 'a' ) ; Here, when n = 1 my code while try to create string of a's with length -1. So this was the reason for this runtime error in my case. So i handled this edge case before this line of code.