You are not logged in. Please login at www.codechef.com to post your questions!

×

SPREAD2 sigsegv error

https://www.codechef.com/viewsolution/20671922

why was this solution showing a sigsegv error when I used a prefix sum array to solve the problem? Any help would be appreciated. Thanks in advance.

asked 17 Oct '18, 10:29

eaugene's gravatar image

4★eaugene
445
accept rate: 20%


The only reason i can see is int overflow just make array presum i.e. a and variable i long long. The overflow is causing your variable i to go less than 0 which will make -ve array indexing and hence RE.I guess you will get the idea :)

link

answered 17 Oct '18, 12:14

ram_24's gravatar image

4★ram_24
1586
accept rate: 35%

1

Thanks @ram_24 . A silly mistake costed me 19 penalty attempts.

(17 Oct '18, 15:35) eaugene4★

Yes, the problem occurs at line 21 in your code. If the input is large and value of 'i' gets above INT_MAX, 'i' overflows for next iteration and the indexing gets disturbed ! Hence SIGSEGV.

link

answered 17 Oct '18, 12:54

ayush_0101's gravatar image

3★ayush_0101
512
accept rate: 28%

Thank You @ayush_0101 .

(17 Oct '18, 15:36) eaugene4★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×3,770
×1,682
×483
×215
×29
×5

question asked: 17 Oct '18, 10:29

question was seen: 522 times

last updated: 17 Oct '18, 15:36