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

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

1831B - Array merging

When i submit it is showing 'out of bounds' error but the other solution is getting accepted the only difference is that i have used two one dimensional array and he have used one two dimensional array.

Error submission: 242771431 Accepted submission: 242771679

Please help, why am i getting the error?

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

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

According to my logic , your second solution should also be with 'out of bounds' because in the

for (int i = 0; i < n; i++) 
 if (a[i] == a[i - 1])
     cnt++
 else
     cnt = 1;

you are going beyond the index of the variable i = -1 which does not exist.

Here is your corrected solution, I increased the length of the array and also added 2 if

if (i == 0) cnt = 1 

corrected solution