My submission:- https://pastebin.com/aL9vCYWu

Please anyone tell what is wrong in this code

# | User | Rating |
---|---|---|

1 | tourist | 3697 |

2 | Benq | 3583 |

3 | Petr | 3522 |

4 | ecnerwala | 3467 |

5 | Radewoosh | 3466 |

6 | maroonrk | 3369 |

7 | Um_nik | 3358 |

8 | jiangly | 3330 |

9 | Miracle03 | 3314 |

10 | scott_wu | 3313 |

# | User | Contrib. |
---|---|---|

1 | 1-gon | 214 |

2 | Errichto | 189 |

3 | awoo | 188 |

4 | rng_58 | 187 |

5 | SecondThread | 186 |

6 | Um_nik | 179 |

7 | Ashishgup | 177 |

8 | maroonrk | 172 |

8 | vovuh | 172 |

8 | antontrygubO_o | 172 |

My submission:- https://pastebin.com/aL9vCYWu

Please anyone tell what is wrong in this code

↑

↓

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/16/2021 20:24:40 (j3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Share your submission using pastebin.com

Sorry Bro I forgot that it was not accessible publically. My bad

Auto comment: topic has been updated by Mohd__Messi (previous revision, new revision, compare).you can solve it with a one dimension dp array like this

first set the whole array to -inf execpt dp[0] = 0

for(int i = 2; i < 10001;++i)

for(int x : v) // v is the vector that hold prime numbers and primatic numbers

{

if(i — x < 0)continue;

dp[i] = min(dp[i], dp[i — x] + 1);

}

answer = dp[input]

With

`N = 9973`

(the largest prime below 10 000), your code prints`0`

.Yes but why I am not able to counter that my DP solution seems OK but last few cases are giving WA. Can you please give a hint.

You aren't using last prime number

`v[m - 1]`

in your dp loop, because you are going from`1..m-1 (for i)`

, but then you are using`v[i - 1]`

in calculation, so in reality you are using`0..m-2`

prime numbers.Second problem is array overflow, because in your

`for(;l<v.size();l++)`

for number like 10000 you will end up with`l == m`

, which doesn't with your`dp`

declaration.To fix it change

`int dp[m][10001]`

to`int dp[m+1][10001]`

and also your dp loop from`for(int i=0;i<m;i++)`

to`for(int i=0;i<=m;i++)`

. That being said, you don't need 2 dimensional array, as pointed out by Mohamed_Saad62Thanks a lot brother I passed the last case. I declared dp[m][10001] thats why the last prime number was not getting included. Thanks a lot for pointing out my mistake.