I'm getting WA can anyone tell me what I'm doing wrong or the test case which fails in this. asked 21 Jan '13, 13:39
converted to question 21 Jan '13, 14:14

Try this test: 4 0 4 2 12 2 1 9 24 0 1 9 12 2 8 2 18The answer is 2. While your answer is 12. UPD. answered 21 Jan '13, 14:07
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)
Hi Anton, I was checking this link: http://discuss.codechef.com/questions/5196/chefhackcompiler and you have posted the same test case with 12 as the answer! nnovoice
(25 Jan '13, 09:06)
Sorry, I've swapped the correct and yours answers :P
(25 Jan '13, 14:35)
Thank you. BTW, that was not my answer! nnovoice
(25 Jan '13, 16:39)
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)
1
The reason is stack overflow in DFS.
(15 Feb '13, 02:07)
Thank you Anton! I will try that.
(15 Feb '13, 06:36)
I tried vector<int> 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)
showing 5 of 8
show all

@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
