結果

問題 No.4 おもりと天秤
ユーザー urunea
提出日時 2025-04-22 01:31:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 419 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 82,776 KB
実行使用メモリ 64,748 KB
最終ジャッジ日時 2025-04-22 01:31:25
合計ジャッジ時間 2,851 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
W=list(map(int, input().split()))
sum_w=sum(W)
if sum_w%2 == 1:
    print("impossible")
    exit()
sum_w //= 2
dp=[[False]*(sum_w+1) for i in range(N+1)]
dp[0][0] = True

for i in range(N):
    for j in range(sum_w+1):
        if dp[i][j] == True:
            dp[i+1][j] = True
            if j + W[i] < sum_w + 1:
                dp[i+1][j+W[i]] = True

print("possible" if dp[-1][-1] else "impossible")
0