結果

問題 No.4 おもりと天秤
ユーザー HiroK_abc
提出日時 2017-06-17 10:13:49
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 472 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-06-26 10:19:28
合計ジャッジ時間 1,944 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
ws = list(map(int, input().split()))
W = sum(ws) // 2

if sum(ws) % 2 != 0:
    print('impossible')
elif W < max(ws):
    print('impossible')
else:
    weight = set([0])
    ws.sort()
    while len(ws) > 0:
        w = ws.pop()
        tmp_set = set()
        for i in weight:
            if i + w <= W:
                tmp_set.add(i + w)
        weight.update(tmp_set)
    if W in weight:
        print('possible')
    else:
        print('impossible')

0