結果

問題 No.4 おもりと天秤
ユーザー kiccho1101kiccho1101
提出日時 2022-04-23 18:34:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 459 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 84,996 KB
最終ジャッジ日時 2023-09-07 11:10:24
合計ジャッジ時間 3,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,040 KB
testcase_01 AC 82 ms
76,220 KB
testcase_02 AC 89 ms
76,308 KB
testcase_03 WA -
testcase_04 AC 95 ms
76,128 KB
testcase_05 AC 127 ms
84,628 KB
testcase_06 AC 82 ms
76,352 KB
testcase_07 AC 130 ms
84,740 KB
testcase_08 AC 121 ms
84,456 KB
testcase_09 AC 124 ms
84,548 KB
testcase_10 AC 129 ms
84,716 KB
testcase_11 AC 86 ms
76,096 KB
testcase_12 AC 80 ms
76,088 KB
testcase_13 AC 81 ms
76,032 KB
testcase_14 AC 82 ms
76,112 KB
testcase_15 AC 82 ms
76,420 KB
testcase_16 WA -
testcase_17 AC 85 ms
76,160 KB
testcase_18 AC 129 ms
84,912 KB
testcase_19 AC 126 ms
84,652 KB
testcase_20 AC 131 ms
84,760 KB
testcase_21 AC 127 ms
84,736 KB
testcase_22 AC 128 ms
84,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

# dp[i][j]: i番目までのおもりで左-右がjになるかどうか
dp = [[False] * 10001 for _ in range(N + 1)]

dp[0][0] = True
for i in range(N):
    for j in reversed(range(10001)):
        w = W[i]
        if j + w < 10001:
            dp[i + 1][j] |= dp[i][j + w]
        if j - w >= 0:
            dp[i + 1][j] |= dp[i][j - w]

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