Is this a bug?

The only difference in these submissions is for & while loop in the main()
Solution 1 - WA
Solution 2 - AC
Difference Check
What could be the possible reason ?

1 Like

Ouch:

[simon@simon-laptop][16:42:20]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt
1
15
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
[simon@simon-laptop][16:42:25]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt | ./a.out 
ubc_123-RAINBOWA-ac.cpp:34:16: runtime error: index 7 out of bounds for type 'long long int [7]'
ubc_123-RAINBOWA-ac.cpp:34:16: runtime error: load of address 0x7ffc31046cf8 with insufficient space for an object of type 'll'
0x7ffc31046cf8: note: pointer points here
 00 00 00 00  00 27 da d0 84 c5 f9 ef  14 6d 04 31 fc 7f 00 00  01 00 00 00 00 00 00 00  a0 c6 bc 24
              ^ 
ubc_123-RAINBOWA-ac.cpp:34:17: runtime error: store to address 0x7ffc31046cf8 with insufficient space for an object of type 'll'
0x7ffc31046cf8: note: pointer points here
 00 00 00 00  00 27 da d0 84 c5 f9 ef  14 6d 04 31 fc 7f 00 00  01 00 00 00 00 00 00 00  a0 c6 bc 24
              ^ 
no
*** stack smashing detected ***: <unknown> terminated
Aborted (core dumped)

This line is an out-of-bounds access:

       arr[x-1]++;

when x=8.

3 Likes

@ssjgz could you please check this
https://www.codechef.com/viewsolution/30467678
I have terminated before access but still WA?
What is your generator.cpp ?
I have stress tested this on 100,000 inputs over a small interval
Edit: stress tested using t = 1 so unable to figure out :grin: (cont. i/p stream)

I don’t actually have one for this for one - I just manually add new testcases as I find them :slight_smile:

Consider the re-arranged sample testcase:

3
14
1 2 3 4 5 6 7 6 5 4 3 2 1 1
13
1 2 3 4 5 6 8 6 5 4 3 2 1
19
1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1

Edit: Off for food, so may not reply for a while :slight_smile:

3 Likes

@ssjgz why is my code terminating before reaching

19
1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1
this test case ?

Debug it and find out - you have a 100% reproducible testcase :slight_smile: As a hint: I knew that that testcase would fail before I even tried it :slight_smile:

Edit:

No, wait - I miscalculated. I actually don’t know why that doesn’t work! XD Anyway, off to get food now!

Edit2:

I miscalculated when I said I miscalculated - I know precisely why it works, but somehow forgot since I posted - this is what happens when I don’t get food! XD

2 Likes

got it i/p stream i’m using it partially
Best Bug till now that i’ve faced : ) thanks a lot @ssjgz
Fixed .
image

2 Likes

It’s one I’ve seen before, albeit in a different Problem - trying to remember which one…

Edit:

Maybe this one: CNOTE - Editorial - #33 by ssjgz

2 Likes