結果

問題 No.4 おもりと天秤
ユーザー taisuke
提出日時 2023-02-19 18:24:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 421 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-07-20 17:20:00
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
w = list(map(int, input().split()))
wsum = sum(w)
if wsum % 2 != 0:
    print("impossible")
    exit()

wmax = wsum // 2
dp = [False for j in range(wmax + 1)]
dp[0] = True

for i in range(1, n+1):
    tmp = dp.copy()
    for j in range(wmax + 1):
        if j >= w[i-1]:
            tmp[j] = tmp[j] or dp[j - w[i-1]]
    dp = tmp.copy()

ans = "possible" if dp[wmax] == True else "impossible"
print(ans)
0