I have updated the editorial. Please read and follow the SUGGESTION at the beginning of editorial.
I have updated the editorial. Please read and follow the SUGGESTION at the beginning of editorial.
Thatās great anton_lunyvon. Thanks a lot.
In routines oddserver and evenserver you should check before accessing valid[k][l] (or valid[m][n]) that cell (k,l) (or (m,n)) lies inside the grid. Probably this is the reason.
Your array for primes is too small. Add one zero to K. Like here:
http://www.codechef.com/viewsolution/1745675
@anton_lunyov (valid[i][j] is itself a array which has 1 at (i,j) if i,j lies inside the grid otherwise valid[i][j] contains 0) it is also workin well .please help to sort out this problem ,still unable to fiure out the problem
In evenserver()
instead of
if(!valid[k][l])
return 0;
you should write
if(k<0 || k>=n || l<0 || l>=n || !valid[k][l])
return 0;
where n
is the size of the grid that should be defined globally.
The same should be applied to oddserver()
but be careful you are using variable n
there as y-coordinate of the cell.
If you will have troubles with fixing it you can refer to my edit of your code that got AC:
http://www.codechef.com/viewsolution/1745787
Greatly appreciated, Anton! I should have noticed it by myself!
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ā¦
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: CHEFHACK compiler - general - CodeChef Discuss and you have posted the same test case with 12 as the answer!
-nnovoice
Sorry, Iāve swapped the correct and yours answers
Is this clear your doubt?
approach is as :
- generate prime numbers index.
- read data (simultaneously add attempts for primes). store odd/even flag for remaining.
- 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.
- ātags[i][j]ā for each member is assigned as āi*N+jā.
- 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
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ā¦
Hi Anton,
Would you be able to help me in finding why my solution fails with SIGSEGV: CodeChef: Practical coding for everyone? 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.