BULBS Help -Answer Difference On PC and Online Compiler

So in Todays September Cook-Off 2020 Division 2
I was solving Question Bulbs and Wires

https://www.codechef.com/COOK122B/problems/BULBS

When I ran it on my pc it gave correct ans For the Test Case Given. Ran it again on online Codechef IDE, it gives Different ans (no changes were made).

When Submitted - Runtime Error SIGSEVV
Solution Link- https://www.codechef.com/viewsolution/38080234

My basic concern is why it show diff ans for same test case in Online and offline.

Rough Code Logic -
2 cut a set of bulb from middle we req 2 steps out of K. So we cut Longest 0 sequence.
If k is odd we will cut the max sequence of 0s from start or end if present.
Start and and End req 1 step

[simon@simon-laptop][21:04:31]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling sksama-BULBS.cpp
+ g++ -std=c++14 sksama-BULBS.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
sksama-BULBS.cpp: In function β€˜int main()’:
sksama-BULBS.cpp:118:8: warning: unused variable β€˜y’ [-Wunused-variable]
    int y= x- v[size-1]+max(ss,ee);
        ^
sksama-BULBS.cpp:122:9: warning: unused variable β€˜z’ [-Wunused-variable]
     int z = x - v[size - 1] + x - v[size - 2] + ss + ee;
         ^
+ set +x
Successful
[simon@simon-laptop][21:04:45]
[~/devel/hackerrank/otherpeoples]>cat last-testcase.txt 
1
8 7
00110101
[simon@simon-laptop][21:04:49]
[~/devel/hackerrank/otherpeoples]>cat last-testcase.txt  | ./a.out 
/usr/include/c++/7/debug/vector:417:
Error: attempt to subscript container with out-of-bounds index 2, but 
container only holds 2 elements.

Objects involved in the operation:
    sequence "this" @ 0x0x7fff1cf031d0 {
      type = std::__debug::vector<int, std::allocator<int> >;
    }
Aborted (core dumped)
5 Likes

for example, there are 4 groups of zeroes and k is 200, was the condition included to avoid out of bounds error while traversing the sorted vector?

thanks

1 Like

thank you

1 Like