結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,220 KB
testcase_01 AC 81 ms
76,260 KB
testcase_02 AC 87 ms
76,140 KB
testcase_03 WA -
testcase_04 AC 90 ms
76,232 KB
testcase_05 AC 110 ms
76,288 KB
testcase_06 AC 81 ms
76,052 KB
testcase_07 AC 109 ms
76,180 KB
testcase_08 AC 103 ms
76,268 KB
testcase_09 AC 108 ms
76,284 KB
testcase_10 AC 112 ms
76,256 KB
testcase_11 AC 82 ms
76,120 KB
testcase_12 AC 80 ms
76,232 KB
testcase_13 AC 82 ms
76,220 KB
testcase_14 AC 83 ms
76,104 KB
testcase_15 AC 81 ms
76,048 KB
testcase_16 WA -
testcase_17 AC 85 ms
76,200 KB
testcase_18 AC 110 ms
76,124 KB
testcase_19 AC 110 ms
76,288 KB
testcase_20 AC 123 ms
84,896 KB
testcase_21 AC 123 ms
84,632 KB
testcase_22 AC 109 ms
76,176 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 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