結果

問題 No.1117 数列分割
ユーザー ttrttr
提出日時 2020-07-17 22:58:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 572 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 46,900 KB
最終ジャッジ日時 2023-08-20 04:00:39
合計ジャッジ時間 4,803 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,176 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 16 ms
7,792 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-r-1 < n or 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(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