結果

問題 No.4 おもりと天秤
ユーザー kiccho1101kiccho1101
提出日時 2022-04-23 18:38:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 444 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 76,344 KB
最終ジャッジ日時 2023-09-07 11:10:28
合計ジャッジ時間 3,542 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,956 KB
testcase_01 AC 79 ms
75,964 KB
testcase_02 AC 84 ms
76,012 KB
testcase_03 AC 87 ms
76,304 KB
testcase_04 AC 85 ms
76,116 KB
testcase_05 AC 105 ms
76,144 KB
testcase_06 AC 78 ms
76,152 KB
testcase_07 AC 105 ms
76,344 KB
testcase_08 AC 101 ms
76,188 KB
testcase_09 AC 101 ms
76,080 KB
testcase_10 AC 108 ms
76,184 KB
testcase_11 AC 82 ms
76,128 KB
testcase_12 AC 81 ms
75,960 KB
testcase_13 AC 81 ms
75,908 KB
testcase_14 AC 81 ms
75,960 KB
testcase_15 AC 80 ms
76,156 KB
testcase_16 AC 82 ms
76,172 KB
testcase_17 AC 87 ms
76,068 KB
testcase_18 AC 100 ms
76,212 KB
testcase_19 AC 103 ms
75,964 KB
testcase_20 AC 107 ms
76,148 KB
testcase_21 AC 103 ms
76,144 KB
testcase_22 AC 102 ms
76,128 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]
        dp[i + 1][j] = dp[i][j]
        if j - w >= 0:
            dp[i + 1][j] |= dp[i][j - w]

s = sum(W)
if s % 2 == 1 or not dp[N][s // 2]:
    print("impossible")
else:
    print("possible")
0