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


chefhack -WA

I tried it several times but wrong answer. its running in all test cases i tried. Can any1 provide me test cases where i go wrong?or any help... my soln is: i have used a different method...

1.for prime,i used seive amd marked the numbers which are prime,then binary search to get the index or count of prime......

2.i am looping normally in 2d grid. any number will have 4 neighbours.if we traverse the grid,cost of 3 neighbours of even/odd number will always have been calculated by now if we keep on marking even/odd neighbours and the cost of given server is known.further all its even/odd immediate neighbour which was not marked will be marked 0 now.

actually,if number is even,we find its 4 neighbours.if any neighbour is even and its answer matrix is marked we return the cost for arr[i][j] server is 0.if none of its even neighbour is marked, we mark their cost as 0 because the number which called them is even.

All i say that we dont need dfs. just traverse grid and keep on marken neighbours. its working fine. can anybody help? any test case...

asked 16 Jan '13, 16:14

calci's gravatar image

accept rate: 0%

Nope. Just traversing the grid is not enough.
Consider this simplest case:
4 1 4
4 4 4
1 1 1

When you consider the very first 4 you should mark all other fours by dfs.
But using your method you mark only one four at the cell[2][1]
and when consider the four at the cell[1][3] will count it.


answered 17 Jan '13, 01:44

anton_lunyov's gravatar image

6★anton_lunyov ♦
accept rate: 12%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 16 Jan '13, 16:14

question was seen: 651 times

last updated: 17 Jan '13, 01:44