結果

問題 No.4 おもりと天秤
ユーザー 炭酸水
提出日時 2022-05-13 07:39:24
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 475 bytes
コンパイル時間 475 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-21 04:06:21
合計ジャッジ時間 2,380 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
w = list(map(int, input().split()))

w_sum = 0
for i in w:
    w_sum += i

if w_sum % 2 == 1:
    print("impossible")

elif w_sum % 2 == 0:
    dp = [False for _ in range(w_sum // 2 + 1)]
    dp[0] = True
    for i in range(n):
        dp_i = dp.copy()
        for j in range(w_sum // 2 + 1):
            if dp_i[j] and j + w[i] <= w_sum // 2:
                dp[j + w[i]] = True
    if dp[-1]:
        print("possible")
    else:
        print("impossible")
0