結果

問題 No.1247 ブロック登り
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-04 14:35:59
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,744 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 777,180 KB
最終ジャッジ日時 2024-04-15 06:59:32
合計ジャッジ時間 6,271 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
59,680 KB
testcase_01 AC 37 ms
52,480 KB
testcase_02 AC 38 ms
53,376 KB
testcase_03 AC 37 ms
52,608 KB
testcase_04 AC 48 ms
62,080 KB
testcase_05 AC 41 ms
53,376 KB
testcase_06 AC 37 ms
52,608 KB
testcase_07 AC 309 ms
85,792 KB
testcase_08 AC 305 ms
86,308 KB
testcase_09 AC 242 ms
81,456 KB
testcase_10 AC 248 ms
81,636 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 #

def main1(n,k,a):
  inf=float('inf')
  dp0=[[[-inf]*n for _ in range(n)] for _ in range(k)]
  # dp0[i][l][r]:高さi以上のブロックは構築済みで[l,r]が到達済みでlにいるときの最大得点
  dp1=[[[-inf]*n for _ in range(n)] for _ in range(k)]
  # dp1[i][l][r]:高さi以上のブロックは構築済みで[l,r]が到達済みでrにいるときの最大得点
  for i in range(n):
    if i>0:dp0[k-1][i-1][i]=k*a[i]+(k-1)*a[i-1]
    if i<n-1:dp1[k-1][i][i+1]=k*a[i]+(k-1)*a[i+1]
  ans=[-inf]*n
  for j in range(k-1,0,-1):
    for l in range(n):
      for r in range(l,n):
        if k+1-j<r+1-l:continue
        if dp0[j][l][r]!=-inf:
          # dp0[j][l][r]からの遷移。
          if j-2>=0:dp0[j-2][l][r]=max(dp0[j-2][l][r],dp0[j][l][r])
          if j-1>=0 and l>0:dp0[j-1][l-1][r]=max(dp0[j-1][l-1][r],dp0[j][l][r]+a[l-1]*(j-1))
          # l->rへの移動
          if j-(r-l)>=0:
            dp1[j-(r-l)][l][r]=max(dp1[j-(r-l)][l][r],dp0[j][l][r])
          else:
            ans[l+j]=max(ans[l+j],dp0[j][l][r])

        if dp1[j][l][r]!=-inf:
          # dp2[j][l][r]からの遷移。
          if j-2>=0:dp1[j-2][l][r]=max(dp1[j-2][l][r],dp1[j][l][r])
          if j-1>=0 and r<n-1:dp1[j-1][l][r+1]=max(dp1[j-1][l][r+1],dp1[j][l][r]+a[r+1]*(j-1))
          # l<-rへの移動
          if j-(r-l)>=0:
            dp0[j-(r-l)][l][r]=max(dp0[j-(r-l)][l][r],dp1[j][l][r])
          else:
            ans[r-j]=max(ans[r-j],dp1[j][l][r])
  for l in range(n):
    for r in range(l,n):
      ans[l]=max(ans[l],dp0[0][l][r])
      ans[r]=max(ans[r],dp1[0][l][r])
  return ans

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  ret1=main1(n,k,a)
  print(*ret1,sep='\n')
0