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

Discussion of Problem 1005. Stone Pile

Python -- what's wrong with my code?
Posted by Nin_Jar 22 May 2017 14:54
import sys

nums = map(int, sys.stdin.read().split())
length = nums.pop(0)

result = sum_value = sum(nums)


def calc(deep, total=0, ignore=[]):
    global result
    for i in range(length):
        if i in ignore:
            continue
        t = total + nums[i]
        if deep > 0:
            ignore.append(i)
            calc(deep - 1, t, ignore)
        else:
            diff = abs(sum_value - t * 2)
            if result > diff:
                result = diff
                if result == 0:
                    break


for i in range(length / 2):
    calc(i)
    if result == 0:
        break

print result
Re: Python -- what's wrong with my code?
Posted by Mahilewets 22 May 2017 17:44
Try to use itertools or just bitmasks.
(I can't understand your code.  I got my AC just iterating through all numbers 1...2^N-1)