結果

問題 No.1247 ブロック登り
ユーザー mkawa2mkawa2
提出日時 2021-08-18 17:56:43
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,731 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 849,196 KB
最終ジャッジ日時 2024-04-19 23:28:50
合計ジャッジ時間 4,654 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,696 KB
testcase_01 AC 35 ms
53,208 KB
testcase_02 AC 38 ms
54,496 KB
testcase_03 AC 33 ms
53,612 KB
testcase_04 AC 52 ms
67,488 KB
testcase_05 AC 50 ms
66,408 KB
testcase_06 AC 33 ms
53,816 KB
testcase_07 AC 181 ms
92,360 KB
testcase_08 AC 181 ms
94,364 KB
testcase_09 AC 140 ms
82,024 KB
testcase_10 AC 150 ms
83,508 KB
testcase_11 MLE -
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 #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

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

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

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

for i in range(k, 0, -1):
    for l in range(n):
        for r in range(l, n):
            for j in range(2):
                pre = dp[i][l][r][j]
                if pre == -inf: 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)

ans = [-inf]*n
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][j-i][r][0])
    for l in range(j+1):
        for i in range(k):
            if j+i==n:break
            ans[j]=max(ans[j],dp[i][l][j+i][1])

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