結果

問題 No.4 おもりと天秤
ユーザー taisuke
提出日時 2023-02-19 18:01:44
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 374 ms / 5,000 ms
コード長 462 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2024-07-20 17:01:11
合計ジャッジ時間 3,371 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 i in range(wmax + 1)] for j in range(n + 1)]
dp[0][0] = True

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

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