CHEFHACK - Editorial

Use printf("%lld\n", tries).
I should add this tip to the editorial.
Several guys who asked for help all have this bug:
they use long long but print it as %d

thank you for the correction.
i tried another approachā€¦ facing a similar problemā€¦

http://www.codechef.com/viewsolution/1747532

Wow! Your solution fails for only one grid among 80 grids we have in official test data. It is a grid having the following structure: N=350, a[i][j] are all even non-primes, except very small percent of odd non-primes. Each group of odd passwords is generated as a boundary of a small square.

Your solution is quite hard to follow so I can only suggest you to generate test of the above structure for smaller size and compare your answer with the answer generated by the correct program.

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

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

Sorry, Iā€™ve swapped the correct and yours answers :stuck_out_tongue:
Is this clear your doubt?

approach is as :

  1. generate prime numbers index.
  2. read data (simultaneously add attempts for primes). store odd/even flag for remaining.
  3. get_neighbors() will store ā€˜validā€™ neighbors for each data. ā€˜validā€™ means - (i) it is either [i+1][j] or [i][j+1]. (ii) it has to be of same type (odd/even) non-primes.
  4. ā€˜tags[i][j]ā€™ for each member is assigned as ā€˜i*N+jā€™.
  5. arrange_and_compute() will do traversal over all members and update ā€˜validā€™ neighbors with lowest tags among them. this is done in loop until there is no change in an iteration.

this was an attempt on amortization. will see!

Thank you. BTW, that was not my answer! -nnovoice

Can you please tell whats wrong with my codeā€¦its giving correct output for test casesā€¦

http://www.codechef.com/viewsolution/1752815

You should not pass through the cells containing 2 in mark_check_even. Try this test:

4
0 4 2 12
2 1 9 24
0 1 9 12
2 8 2 18 

The answer is 12 while your answer is 2.

Thanks a lotā€¦

my


[1]  is giving a runtime error(NZEC).Can anyone plz tell what is the problem?


  [1]: http://www.codechef.com/viewsolution/1790006

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

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.

1 Like

Thank you Anton! I will try that.

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!

Can anybody look at my solution and explain why am i getting Runtime error(segmentation fault). i cant see whyā€¦:frowning:

http://www.codechef.com/viewsolution/4125365

my code runs fine on my machine but shows wrong answer on submission
Please help my solution is here http://www.codechef.com/viewsolution/5203370

@anton_lunyov

@i_am_what_i_am

Hi, I just studied DFS and then searched this problem through question tags.
I passed the given test cases and also the cases given in editorial.
But still couldnā€™t get AC.

I made these solutions:

  1. https://www.codechef.com/viewsolution/8801554 ā€”> It gave me WA

  2. https://www.codechef.com/viewsolution/8801563 ā€”> It gave me RE

The only difference between both these solutions is that i have changed my counter variable which is needed to be printed from long to long long.

I would be so glad if anyone could explain me the bug.

struggling from a day with my code here
it gives correct answer to all cases ever in discussion or editorial but still getting a WA.
help would be greatly appreciated