ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
back to board

Discussion of Problem 1005. Stone Pile

WA #9; Code review
Posted by thrashzone 19 Dec 2020 16:17
Hi there!
Here is my code for this task: https://notabug.org/thrashzone_ua/c_examples/src/master/rock_heap.c

Short notes:
1) Cases when there is one or two rocks from input are separated
2) In case amount of rocks is more then 2, I'm checking if there is a sublist in list of rocks with sum(sublist) = sum(list) / 2. If there is such a sublist and the number of sum is even - 0 will be printed, if number is not even - 1;
3) In case there no such sublist - it's time for greedy algorithm.

Could you please take a look and comment my code? Or maybe provide with test set, on which it will fail?

Thank you in advance.
Re: WA #9; Code review
Posted by thrashzone 20 Dec 2020 03:22
So, long story short - do not use greedy algorithm, read and think more about dynamic programming.