結果

問題 No.4 おもりと天秤
ユーザー satama123
提出日時 2023-11-11 23:30:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 63,360 KB
最終ジャッジ日時 2024-09-26 02:55:59
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
W = list(map(int, input().split()))
S = sum(W)

if S & 1 : exit(print("impossible"))
S //= 2
dp = [[False for _ in range(S + 1)] for _ in range(N + 1)]
dp[0][0] = True

for i in range(N):
    w = W[i]

    for s in range(S + 1):
        if not dp[i][s] : continue
        dp[i + 1][s] = True
        if w + s <= S : dp[i + 1][s + w] = True

if dp[N][S] : print("possible")
else : print("impossible")
0