×

# CHEFHACK - WA

 0 I'm getting WA can anyone tell me what I'm doing wrong or the test case which fails in this. http://www.codechef.com/viewsolution/1742653 asked 21 Jan '13, 13:39 1●1●1●1 accept rate: 0% 6.7k●62●119●138

 2 Try this test: 4 0 4 2 12 2 1 9 24 0 1 9 12 2 8 2 18  The answer is 2. While your answer is 12. UPD. The answer is 12. While your answer is 2. answered 21 Jan '13, 14:07 6.7k●62●119●138 accept rate: 12% Hi Anton, Is (1,1) connected to (1,4)? I don't seem to understand the connectivity rules to get to answer 2. Thank you for the small test case. -nnovoice (25 Jan '13, 08:49) nnovoice2★ Hi Anton, I was checking this link: http://discuss.codechef.com/questions/5196/chefhack-compiler and you have posted the same test case with 12 as the answer! -nnovoice (25 Jan '13, 09:06) nnovoice2★ Sorry, I've swapped the correct and yours answers :P Is this clear your doubt? (25 Jan '13, 14:35) Thank you. BTW, that was not my answer! -nnovoice (25 Jan '13, 16:39) nnovoice2★ Hi Anton, Would you be able to help me in finding why my solution fails with SIGSEGV: http://www.codechef.com/viewsolution/1759752? If you could help me with a test case, I will try to find out. I have tried to find a problem in the code without success. Thank you. -nnovoice (14 Feb '13, 17:48) nnovoice2★ 1 The reason is stack overflow in DFS. Try to get rid of arrays rows[] and cols[]. For example, you could make them vectors. Then they will be allocated not in stack. (15 Feb '13, 02:07) Thank you Anton! I will try that. (15 Feb '13, 06:36) nnovoice2★ I tried vector but they slowed down the execution. So, I went with allocating memory on the heap using new. Submitted with correct answer! Thank you! (15 Feb '13, 09:44) nnovoice2★ showing 5 of 8 show all
 0 @cyberghost23 : In your submission , you are using Arrays.binarySearch() . However the length of the array of primes "p" is not exactly the number of primes till the range you have found them . You should store the number of primes which are valid entries in array of primes "p" . And then you should use the method Arrays.binarySearch(int [] array , int fromIndex , int endIndex , int value ) . Pass fromIndex = 0 and endIndex = number of valid prime entries in the array . If you do binary search on the whole array , there are some junk entries in the end of array , which make the results undefined as the array now may not be sorted due to junk entries and binary search will not be able to function properly . answered 16 Feb '13, 12:26 12.4k●47●107●171 accept rate: 12%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×1,070
×21

question asked: 21 Jan '13, 13:39

question was seen: 1,026 times

last updated: 07 Mar '17, 16:47