結果

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

ソースコード

diff #

# coding: utf-8
N = int(input())
W = list(map(int, input().split()))


if sum(W) % 2:
    print("impossible")
else:
    num_sum = sum(W) // 2

    dp = [0] * (sum(W) + 1)
    dp[0] = 1
    total = 0
    for w in W:
        total += w
        for i in range(total, -1, -1):
            if dp[i] == 1:
                dp[i + w] = 1
    
    if dp[num_sum]:
        print("possible")
    else:
        print("impossible")
0