結果

問題 No.4 おもりと天秤
ユーザー qewqewqew
提出日時 2018-12-15 03:04:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 274 ms / 5,000 ms
コード長 467 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2024-09-25 05:42:44
合計ジャッジ時間 2,646 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

sum_w = sum(ws)
if sum_w % 2:
    print("impossible")
    exit()

dp = [[False]*(sum_w//2+1) for i in range(n+1)]
dp[0][0] = True
for i in range(1, n+1):
    for w in range(sum_w//2+1):
        if w - ws[i-1] >= 0:
            dp[i][w] = dp[i-1][w] or dp[i-1][w-ws[i-1]]
        else:
            dp[i][w] = dp[i-1][w]

if any([dp[i][-1] for i in range(n+1)]):
    print("possible")
else:
    print("impossible")
0