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

×

CHEFHACK - WA

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

cyberghost23's gravatar image

1★cyberghost23
1111
accept rate: 0%

converted to question 21 Jan '13, 14:14

anton_lunyov's gravatar image

6★anton_lunyov ♦
6.7k62119138


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.

link

answered 21 Jan '13, 14:07

anton_lunyov's gravatar image

6★anton_lunyov ♦
6.7k62119138
accept rate: 12%

edited 25 Jan '13, 16:44

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) anton_lunyov ♦6★

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) anton_lunyov ♦6★

Thank you Anton! I will try that.

(15 Feb '13, 06:36) nnovoice2★

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) nnovoice2★
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 .

link

answered 16 Feb '13, 12:26

vineetpaliwal's gravatar image

6★vineetpaliwal
12.4k47107171
accept rate: 12%

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:

×1,070
×21

question asked: 21 Jan '13, 13:39

question was seen: 1,026 times

last updated: 07 Mar '17, 16:47