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


Help me to debug the catch

for the problem , i designed a code based on Suffix array with LCP but i don't know why one code is accepted and another code is gave SIGSEGV error.

In accepted code i declare extra array B[100010] at line 9 but in second code i comment this array and in both code i don't use this array ................... you can change array name at line 9 as you want but if you comment the array then its shows runtime error.

Admin please help me to finding out the catch.

asked 13 Aug '14, 11:23

maheiitr's gravatar image

accept rate: 25%

edited 13 Aug '14, 12:54

same problem i also face on spoj

(13 Aug '14, 11:42) maheiitr5★

Hi maheiitr, I modified the C array and resized it to 10^5, then it got AC.

- int T,x,y,n,A[100003],SA[100003],RA[100003],temp[100003],C[510];
- int B[100003];
+ int T,x,y,n,A[100003],SA[100003],RA[100003],temp[100003],C[100003];

It is because the RA[] values can be up to 10^5, but your old array was just ~500 big. In your old code, I suspect, that the C array lies just behind the B array in the memory. That's why, if you access for example C[510], it will actually be B[0]. It is just a typical effect of the C++ language, where access out of memory is hard to catch :)

| ~~~~~500~~~~~~|~~~~~~~~~~~~~10^5~~~~~~~~~~~~~~~~|    

answered 14 Aug '14, 15:08

gdisastery1's gravatar image

accept rate: 11%

edited 14 Aug '14, 15:09

but why we go beyond the bound of C array ,its mention in qn that diff b/w two adj values is [-100,100] so maximum we can use C array upto 300 but i took 510 size that's enough for qn requirement

(14 Aug '14, 15:36) maheiitr5★

RA[] value goes upto 300 not 10^5

(14 Aug '14, 15:38) maheiitr5★

It goes up to 10^5 because the each of the suffixes must have a different ranking. Otherwise, how are you going to differ each entry of the suffix array? You compare with the RA[]'s, which can go up to 10^5.

(14 Aug '14, 15:47) gdisastery14★

oh thanx buddy for pointing out my mistake

(14 Aug '14, 22:24) maheiitr5★
toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 13 Aug '14, 11:23

question was seen: 757 times

last updated: 14 Aug '14, 22:24