結果

問題 No.1117 数列分割
ユーザー ttrttr
提出日時 2020-07-17 23:12:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 566 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 222,440 KB
最終ジャッジ日時 2023-08-20 04:07:09
合計ジャッジ時間 5,434 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,496 KB
testcase_01 AC 71 ms
71,020 KB
testcase_02 AC 71 ms
71,200 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K,M = map(int, input().split())
A = [int(a) for a in input().split()]

S = [0]*(N+1)
for i in range(N):
    S[i+1] = S[i]+abs(A[i])
S2 = [0]*(N+1)
for i in range(N):
    S2[i+1] = S2[i]+A[i]

memo = {}
def f(l, r, n):
    if n*M < N-r-1:
        return 0
    if (l, r, n) in memo:
        return memo[(l, r, n)]
    res = abs(S2[r+1]-S2[l])
    temp = 0
    for i in range(r+1, min(N-n+1, r+1+M, N)):
        temp = max(temp, f(r+1, i, n-1))
    memo[(l, r, n)] = res+temp
    return res+temp

ans = 0
for r in range(M):
    ans = max(ans, f(0, r, K-1))
print(ans)
0