WA in CHEFHACK

chefhack
in
wa

#1

but still i am getting wrong answer ?? please point out my mistake …??
http://www.codechef.com/viewsolution/1724277/


#2

You should use long long for count.
It is mentioned in the quick explanation section of the editorial.
I have even made this bold in the editorial now :slight_smile:

But it is not the only issue.
Your code is formatted very bad. Try to clean up and utilize it.
Otherwise nobody will help you.

Also don’t post code as questions they are parsed into some ugly creatures by MarkDown.
You should post link to your code instead.
The best is the link to codechef submission.
Links from ideone.com is not convenient to follow.


#3

still i am getting the wrong answer … i have gone through my code properly …but i am not getting why is it WA.
http://www.codechef.com/viewsolution/1725495

plz help …???


#4

You should use printf("%lld ", count).
Also this
if(mymap.find(a*[j])!=mymap.end())
is bad since it will cost you TLE on the test where all passwords are prime.
I’ve suggested you another way.

Also in your dfs routines it is wrong to check a[i-1][j] without checking that i > 0. In this case you are accessing some wrong cell and anything could happen. But probably in your implementation this does not happen. But it is general suggestion to check the correctness cell before accessing to it.

Of course the same is true for other cells.


#5

Finally I realize your main mistake in your dfs routines you will mark prime numbers as well. You should check in addition to a*[j]%2!=0 also that a*[j] is not prime.

And IMHO your code is very ugly and you should reiterate the style and logic you are using when writing the code.

You have many similar pieces of codes and some not very safe or redundant checks.


#6

okkk!!! i got what you said .
and i have changed the code as suggested by @anton_lunyov in the previous comment .
but still the code is not giving answer correct .
http://www.codechef.com/viewsolution/1725860
it is passing the test case which i am trying but some corner test cases are missing .
there is a minor mistak and i am unable to get it …
plz suggest …??


#7

You have the silliest bug ever in sieve.
Check my edit of your code that finally got AC:
http://www.codechef.com/viewsolution/1726408
I have delete just 6 characters from one line from your code above :wink:


#8

thanks for your valuable response … as a beginner i learnt alot in this problem…:slight_smile:


#9

Good. So I closed your question. It will be a good move from your side to mark my answer as accepted so that I will receive at least some award for spending so much time on fixing your bugs.