結果

問題 No.4 おもりと天秤
ユーザー szkhtsszkhts
提出日時 2022-02-06 09:21:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 341 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,652 KB
実行使用メモリ 8,096 KB
最終ジャッジ日時 2023-09-02 06:58:06
合計ジャッジ時間 4,095 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,096 KB
testcase_01 AC 28 ms
8,000 KB
testcase_02 AC 51 ms
7,932 KB
testcase_03 AC 37 ms
7,820 KB
testcase_04 AC 55 ms
8,008 KB
testcase_05 AC 242 ms
7,972 KB
testcase_06 AC 21 ms
7,968 KB
testcase_07 AC 248 ms
7,988 KB
testcase_08 AC 249 ms
7,968 KB
testcase_09 AC 246 ms
8,028 KB
testcase_10 AC 249 ms
8,032 KB
testcase_11 AC 33 ms
8,092 KB
testcase_12 AC 22 ms
8,040 KB
testcase_13 AC 22 ms
8,092 KB
testcase_14 AC 26 ms
8,020 KB
testcase_15 AC 23 ms
8,000 KB
testcase_16 AC 35 ms
8,024 KB
testcase_17 AC 33 ms
8,000 KB
testcase_18 AC 237 ms
7,968 KB
testcase_19 AC 248 ms
7,996 KB
testcase_20 AC 248 ms
7,984 KB
testcase_21 AC 249 ms
8,004 KB
testcase_22 AC 256 ms
7,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX = 10105
dp = [False] * MAX
N = int(input())
weights = list(map(int, input().split()))
sum = 0
for w in weights:
    sum += w

dp[0] = True
for i in range(N):
    for j in range(MAX - 1 - weights[i], -1, -1):
        dp[j + weights[i]] |= dp[j]

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