結果

問題 No.4 おもりと天秤
ユーザー AEnAEn
提出日時 2022-05-16 16:08:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 450 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 87,204 KB
実行使用メモリ 85,200 KB
最終ジャッジ日時 2023-10-12 09:17:24
合計ジャッジ時間 3,289 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,468 KB
testcase_01 AC 70 ms
71,564 KB
testcase_02 AC 79 ms
76,216 KB
testcase_03 AC 76 ms
76,220 KB
testcase_04 AC 85 ms
76,312 KB
testcase_05 AC 109 ms
81,512 KB
testcase_06 AC 72 ms
71,252 KB
testcase_07 AC 108 ms
81,672 KB
testcase_08 AC 71 ms
71,684 KB
testcase_09 AC 107 ms
85,200 KB
testcase_10 AC 108 ms
81,984 KB
testcase_11 AC 74 ms
76,040 KB
testcase_12 AC 70 ms
71,256 KB
testcase_13 AC 72 ms
71,544 KB
testcase_14 AC 70 ms
71,456 KB
testcase_15 AC 70 ms
71,396 KB
testcase_16 AC 76 ms
76,080 KB
testcase_17 AC 71 ms
71,420 KB
testcase_18 AC 92 ms
76,188 KB
testcase_19 AC 97 ms
76,316 KB
testcase_20 AC 98 ms
76,088 KB
testcase_21 AC 97 ms
76,308 KB
testcase_22 AC 96 ms
76,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

sm = sum(W)
if sm%2 == 1:
    print('impossible')
    exit()
dp = [[True]+[False]*sm for _ in range(N)]
dp[0][W[0]] = True
for i in range(1, N):
    for j in range(sm+1):
        if dp[i-1][j] == True:
            dp[i][j] = dp[i-1][j]
        if j - W[i] >= 0 and dp[i-1][j-W[i]]==True:
            dp[i][j] = dp[i-1][j-W[i]]
if dp[-1][sm//2]:
    print('possible')
else:
    print('impossible')
0