結果

問題 No.2840 RGB Plates
ユーザー suosuo
提出日時 2024-07-11 16:02:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 438 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 65,652 KB
最終ジャッジ日時 2024-08-18 00:55:26
合計ジャッジ時間 5,081 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,336 KB
testcase_01 AC 34 ms
52,704 KB
testcase_02 AC 44 ms
60,316 KB
testcase_03 AC 77 ms
61,468 KB
testcase_04 AC 33 ms
53,212 KB
testcase_05 AC 212 ms
65,652 KB
testcase_06 AC 44 ms
61,648 KB
testcase_07 AC 47 ms
61,428 KB
testcase_08 AC 43 ms
60,900 KB
testcase_09 AC 50 ms
62,496 KB
testcase_10 AC 179 ms
64,412 KB
testcase_11 AC 44 ms
60,816 KB
testcase_12 AC 185 ms
63,748 KB
testcase_13 AC 126 ms
63,720 KB
testcase_14 AC 166 ms
65,076 KB
testcase_15 AC 152 ms
65,468 KB
testcase_16 AC 136 ms
63,592 KB
testcase_17 AC 165 ms
64,520 KB
testcase_18 AC 244 ms
64,472 KB
testcase_19 AC 238 ms
65,304 KB
testcase_20 AC 246 ms
63,684 KB
testcase_21 AC 245 ms
64,308 KB
testcase_22 AC 255 ms
63,828 KB
testcase_23 AC 66 ms
62,544 KB
testcase_24 AC 65 ms
63,120 KB
testcase_25 AC 70 ms
64,020 KB
testcase_26 AC 171 ms
63,460 KB
testcase_27 AC 142 ms
62,704 KB
testcase_28 AC 144 ms
63,408 KB
testcase_29 AC 171 ms
63,636 KB
testcase_30 AC 241 ms
63,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))

if n >= 200:
    mx = 10**4
else:
    mx = sum(a) // 2

dp = [0] * (mx + 1)
dp[0] = 1
for i in a:
    for j in range(mx - 1, -1, -1):
        if i + j > mx:
            continue
        dp[j + i] += dp[j]
        dp[j + i] = min(dp[j + i], 2)
    # print(dp)

for i in range(mx + 1):
    if dp[i] >= 2:
        print(sum(a) - 2 * i if sum(a) - 2 * i else -1)
        exit()
print(-1)
0