ManikantanV's blog

By ManikantanV, 9 years ago, In English

Hi! I am unable to detect the bug in my code problem "Ilya and sticks". I have covered separate cases for number of sticks (>=4,=3,=2,=1). Help is appreciated.Thanks

Code link:

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
9 years ago, # |
Rev. 5   Vote: I like it +1 Vote: I do not like it

i have corrected your code: this is the link that got AC.
as you can see i have added some segments of code like:

if ( modify[i] > 0 && modify[i] < 4 )
    modify[i] = 0;
else if ( modify[i] >= 4 )
    modify[i] -= 4;

this ensures that the number of modifies are minimal so in the every if that they are checked there will be no problem.
plus i changed the if statements that check modify, take a look.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    My original code failed to decrement modify[i] whenever possible with each used stick when h[i]>=4. Everything else was in order.Thanks for pointing out Corrected code is here

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks :) .. i failed to apply greedy in the sense that it would be sensible to use modified sticks first to make rectangles in place of original length sticks.