結果

問題 No.4 おもりと天秤
ユーザー satama123satama123
提出日時 2023-11-11 23:30:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 63,924 KB
最終ジャッジ日時 2023-11-11 23:30:17
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 43 ms
59,652 KB
testcase_03 AC 43 ms
59,652 KB
testcase_04 AC 43 ms
59,652 KB
testcase_05 AC 52 ms
63,916 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 50 ms
63,916 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 48 ms
63,748 KB
testcase_10 AC 50 ms
63,912 KB
testcase_11 AC 41 ms
59,524 KB
testcase_12 AC 38 ms
53,460 KB
testcase_13 AC 38 ms
53,460 KB
testcase_14 AC 38 ms
53,460 KB
testcase_15 AC 37 ms
53,460 KB
testcase_16 AC 41 ms
59,524 KB
testcase_17 AC 38 ms
53,460 KB
testcase_18 AC 48 ms
61,820 KB
testcase_19 AC 50 ms
63,924 KB
testcase_20 AC 52 ms
63,916 KB
testcase_21 AC 51 ms
63,924 KB
testcase_22 AC 49 ms
61,828 KB
権限があれば一括ダウンロードができます

ソースコード

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