結果

問題 No.1247 ブロック登り
ユーザー mkawa2mkawa2
提出日時 2021-08-18 18:14:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,875 ms / 3,000 ms
コード長 1,410 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 334,536 KB
最終ジャッジ日時 2024-04-19 23:46:16
合計ジャッジ時間 36,191 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,424 KB
testcase_01 AC 36 ms
52,716 KB
testcase_02 AC 39 ms
54,656 KB
testcase_03 AC 34 ms
53,412 KB
testcase_04 AC 52 ms
68,128 KB
testcase_05 AC 50 ms
67,224 KB
testcase_06 AC 34 ms
54,152 KB
testcase_07 AC 154 ms
80,528 KB
testcase_08 AC 163 ms
80,720 KB
testcase_09 AC 135 ms
79,336 KB
testcase_10 AC 132 ms
78,844 KB
testcase_11 AC 2,798 ms
334,036 KB
testcase_12 AC 2,632 ms
321,888 KB
testcase_13 AC 2,829 ms
334,536 KB
testcase_14 AC 2,875 ms
334,020 KB
testcase_15 AC 2,811 ms
334,084 KB
testcase_16 AC 2,793 ms
333,816 KB
testcase_17 AC 2,773 ms
334,328 KB
testcase_18 AC 2,522 ms
310,984 KB
testcase_19 AC 324 ms
117,044 KB
testcase_20 AC 181 ms
93,108 KB
testcase_21 AC 54 ms
73,796 KB
testcase_22 AC 214 ms
84,860 KB
testcase_23 AC 194 ms
83,900 KB
testcase_24 AC 44 ms
66,068 KB
testcase_25 AC 2,811 ms
333,772 KB
testcase_26 AC 2,781 ms
333,632 KB
testcase_27 AC 2,765 ms
333,872 KB
testcase_28 AC 2,808 ms
333,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def LI(): return list(map(int, sys.stdin.readline().split()))
inf = 10**9

from array import array

n, k = LI()
aa = LI()
dp = [[[array('i', [-inf]*n) for _ in range(n)] for _ in range(2)] for _ in range(k+1)]

for i, a in enumerate(aa):
    dp[k][0][i][i] = a*k

def chmax(i, l, r, j, val):
    if val > dp[i][j][l][r]: dp[i][j][l][r] = val

ans = [-inf]*n
for i in range(k, -1, -1):
    for l in range(n):
        for r in range(l, n):
            for j in range(2):
                pre = dp[i][j][l][r]
                if pre == -inf: continue
                p0 = r-i if j else l+i
                if l <= p0 <= r: ans[p0] = max(ans[p0], pre)
                if i == 0: continue
                # 左に出る
                d = r-l+1 if j else 1
                if l-1 >= 0 and i-d >= 0: chmax(i-d, l-1, r, 0, pre+(i-d)*aa[l-1])
                # 右に出る
                d = 1 if j else r-l+1
                if r+1 < n and i-d >= 0: chmax(i-d, l, r+1, 1, pre+(i-d)*aa[r+1])
                # 動かない
                if l != r: chmax(i-2, l, r, j, pre)

# for j in range(n):
#     for r in range(j, n):
#         for i in range(k):
#             if j-i < 0: break
#             ans[j] = max(ans[j], dp[i][0][j-i][r])
#     for l in range(j+1):
#         for i in range(k):
#             if j+i == n: break
#             ans[j] = max(ans[j], dp[i][1][l][j+i])

print(*ans, sep="\n")
0