Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4612612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:25:33+00:00 2026-05-22T01:25:33+00:00

Yesterday I paticipated in the Google code jam contest. There were that candy splitting

  • 0

Yesterday I paticipated in the Google code jam contest. There were that candy splitting problem.
http://code.google.com/codejam/contest/dashboard?c=975485#s=p2

I designed an algorithm that basically tries all different combinations for Patrick’s pile and Sean’s pile, checks if they have the same Patrick value, and finally choose the combinations that would maximize Sean’s share. The algorithm worked well for the small imput file. For the large one, I got memory problems and the output never showed up. I believe there muct be another approach to this problem that wouldnt require considering all combinations. Can anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:25:34+00:00Added an answer on May 22, 2026 at 1:25 am

    For the small input, the number of candies are small (upto 15). A search of all possible cases will consist of 2^15 = 32768 possibilities, which can be checked within a millisecond or so. But with upto 1000 candies (large input), the number of possible combinations go upto 2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376. Now this number is a little too big, and even if your run the program for a few years, you are not going to get the result.

    There are some observations which help in making an efficient program for this:

    • Like @Protostome pointed out, the sum that Patrick’s sum is actually an xor operation.
    • Again like @Protostome pointed out, if it is solvable, the xor of all the candies will be 0. Reason is this: if it is possible to have the same xor sum in the two partitions, then taking the xor of both the partitions will be a xor a = 0.
    • If it is possible to partition, then the xor sum of all candies is 0. But, if we remove a single candy from the set of entire candies, it becomes non-zero. Particularly,

    .

       c1 xor c2 xor ... xor ci-1 xor ci xor ci+1 xor ... xor cn = 0
    => c1 xor c2 xor ... xor ci-1     xor    ci+1 xor ... xor cn = ci
    

    That is, we can partition the set into two, by taking out a single candy from the entire set. To maximize the arithmatic sum of the left half, we have to take the candy with the lowest value. So, arithmatic sum of candies in the higher pile is sum of all candies – value of lowest!

    Therefore, we have:

    1. If the xor of all candies is zero, it is solvable
    2. If it is solvable, sum is sum of entire list – lowest value.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I installed mercurial on bluehost by following the instructions found here. http://bugtracker.gttools.com/public/wiki/bluehost/Mercurial When
Yesterday I discovered an odd bug in rather simple code that basically gets text
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
Yesterday, I have a discussion with my colleagues about HTTP. It is asked why
Yesterday I ran into a situation (which I resolved by studying my code a
Yesterday, I asked this question and never really got an answer I was really
Yesterday, I discovered the Subversion (SVN) blame feature, and I was wondering, is this
Yesterday I was having a heated debate with a coworker on what would be
Yesterday I thought it would be nice to implement my own Trigger in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.