結果

問題 No.4 おもりと天秤
ユーザー るさ
提出日時 2018-06-03 17:35:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 340 ms / 5,000 ms
コード長 477 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-06-30 09:25:35
合計ジャッジ時間 3,234 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import copy
n=int(input())
w=list(map(int,input().split()))
hw=int(sum(w)/2)
if hw*2!=sum(w):
    print("impossible")
else:
    table=[0 for i in range(hw+1)]
    table[0]=1
    for i in w:
        ntable=copy(table)
        for j in range(hw+1):
            try:
                ntable[j+i]=max(table[j+i],table[j])
            except:
                pass
        table=copy(ntable)
    if table[-1]==1:
       print("possible")
    else:
       print("impossible")
0