MAX GCD POTPOURRI

Why my code is not getting accepted? Can anyone help in debugging it?
Question Link : CodeChef: Practical coding for everyone
Solution Link : D4eCUM - Online C++0x Compiler & Debugging Tool - Ideone.com

1 Like

I don’t understand you code but here’s my accepted solution Link

See, I dont have an answer of why at present but after replacing you cout statement with this one

cout<<max(max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]),3);
it gives a AC
here is the link
https://www.codechef.com/viewsolution/42876886
Link to the comment from where i got to knew about this

Thank You for helping me out .
But what I don’t understand is why is it necessary to take 3 in the max statement .
I think DP would take all the cases into its consideration.

As I guessed, this solution is incorrect, it passed just cause the test-cases were weak, check this.

TEST_CASE
1
7
12 5 11 3 11 13 7

Correct output is 4 but following this approach will give 3. @misharta

2 Likes

Thanks mann , I got the mistake.

1 Like