結果

問題 No.4 おもりと天秤
ユーザー shinshin
提出日時 2022-10-12 23:06:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 824 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-26 11:31:25
合計ジャッジ時間 7,444 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#おもりと天秤

N = 0
W = []
total = 0

def sumup(s , sum):
    if s > N // 2 and sum == 0:
        return False
    else:
        for i in range(s , N):
            sum += W[i]
            if sum == total:
                return True
            elif sum < total:
                if i + 1 < N:
                    if sumup(i + 1 , sum):
                        return True
                    else:
                        sum -= W[i]
                        return sumup(i + 1 , sum)
                else:
                    return False
            
            

N = int(input())
W = list(map(int , input().split()))

for i in W:
    total += i

W.sort()

if total % 2 == 1:
    print("impossible")
else:
    total = total // 2
    if sumup(0 , 0):
        print("possible")
    else:
        print("impossible")

0