結果

問題 No.4 おもりと天秤
コンテスト
ユーザー Dexctersu
提出日時 2017-12-20 00:19:07
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 431 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 364 ms
コンパイル使用メモリ 20,568 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2026-03-13 02:48:11
合計ジャッジ時間 3,844 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n=int(input())
w=list(map(int,input().split()))
if sum(w)%2!=0:
    print("impossible")
else:
    w_i=sum(w)//2
    weight=set([0])
    w.sort()
    while 0<len(w):
        crt_weight=w.pop()
        tmp_set=set()
        for i in weight:
            if i+crt_weight<=w_i:
                tmp_set.add(i+crt_weight)
        weight.update(tmp_set)
    if w_i in weight:
        print("possible")
    else:
        print("impossible")
0