結果
| 問題 | No.2840 RGB Plates |
| コンテスト | |
| ユーザー |
kidodesu
|
| 提出日時 | 2026-07-23 18:15:52 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 574 bytes |
| 記録 | |
| コンパイル時間 | 243 ms |
| コンパイル使用メモリ | 95,984 KB |
| 実行使用メモリ | 303,104 KB |
| 最終ジャッジ日時 | 2026-07-23 18:15:58 |
| 合計ジャッジ時間 | 5,672 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 1 TLE * 1 -- * 25 |
ソースコード
def main():
n = int(input())
A = list(map(int, input().split()))
N = 10**5
inf = 1<<60
dp = [inf] * (2*N+1)
a = A[0]
dp[a] = a
dp[-a] = a
for a in A[1:]:
ndp = dp[:]
for b in range(-N, N+1):
if -N <= b-a:
ndp[b-a] = min(ndp[b-a], dp[b]+a)
if b+a <= N:
ndp[b+a] = min(ndp[b+a], dp[b]+a)
dp = ndp
#print(dp[-10:] + ["OK"] + dp[:10])
ans = dp[0]
if ans < inf and ans != sum(A):
return sum(A)-ans
else:
return -1
print(main())
kidodesu