Unable to find the mistake ( C- Barcode 225 Div2 ) - Please Help

Problem Link:- C-Barcode
My Code :- My Code

Ive been struggling for 5 hours straight and I’m still not able to find the solution to and get an AC in the problem . You can get the question above . My approach is just like the editorial

Approach :
let’s look on Nxi rectangle formed with the first i columns. What can we say about its last stripe? Either it’s black or white and his width is ranged from x to y. Let’s imagine the last stripe in your subrectangle is white. It means that previous stripe’s color has to be the different (black). Then, for each a x <= a <= y check the cost of oainting rectangle Nx(i-a) in stripes so it will end with the black stripe (dp[1][i-a])and add the cost of painting columns from i-a+1 to i in white (sum-of-whites(i-a+1,i)). Then we keep the best outcome.

Same thing with the case, where the last stripe in rectangle Nxi is white, but with reverse colouring.

I’m Not able to get the answer , somebody Please help .

There are just two minor problems
1.do memset(&dp,INT_MAX,sizeof(dp))
as it will take negative or garbage value if done memset(dp,INT_MAX,sizeof(dp)).
2.initialize sum[0]=0 and run that loop to i<=m not i<m.
here is link of my code my code

1 Like

Thank you very much sir for helping me see my mistakes .

your welcome and don’t call me sir.