結果

問題 No.1247 ブロック登り
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-04 15:32:45
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,020 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 557,732 KB
最終ジャッジ日時 2024-04-15 07:51:25
合計ジャッジ時間 6,635 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
60,860 KB
testcase_01 AC 39 ms
53,080 KB
testcase_02 AC 58 ms
58,116 KB
testcase_03 AC 40 ms
52,332 KB
testcase_04 AC 46 ms
59,376 KB
testcase_05 AC 45 ms
60,156 KB
testcase_06 AC 40 ms
53,416 KB
testcase_07 AC 249 ms
86,848 KB
testcase_08 AC 254 ms
87,264 KB
testcase_09 AC 199 ms
81,772 KB
testcase_10 AC 201 ms
80,788 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 main2(n,k,a):
  inf=float('inf')
  dpl0=[[-inf]*n for _ in range(n)]
  dpl1=[[-inf]*n for _ in range(n)]
  dpr0=[[-inf]*n for _ in range(n)]
  dpr1=[[-inf]*n for _ in range(n)]
  for i in range(n):
    if i>0:dpl0[i-1][i]=k*a[i]+(k-1)*a[i-1]
    if i<n-1:dpr0[i][i+1]=k*a[i]+(k-1)*a[i+1]
  ans=[-inf]*n
  lrary=[{} for _ in range(k)]
  for j in range(k-1,-1,-1):
    dpl2=[[-inf]*n for _ in range(n)]
    dpr2=[[-inf]*n for _ in range(n)]
    ary=lrary.pop()
    for key,v in ary.items():
      f,l,r=key
      if f:
        dpr0[l][r]=max(dpr0[l][r],v)
      else:
        dpl0[l][r]=max(dpl0[l][r],v)
    for l in range(n):
      for r in range(l,n):
        if k+1-j<r+1-l:break
        if dpl0[l][r]!=-inf:
          # dpl0[l][r]からの遷移。
          if j-2>=0:dpl2[l][r]=max(dpl2[l][r],dpl0[l][r])
          if j-1>=0 and l>0:dpl1[l-1][r]=max(dpl1[l-1][r],dpl0[l][r]+a[l-1]*(j-1))
          # l->rへの移動
          if j-(r-l)>=0:
            if (1,l,r)in lrary[j-(r-l)]:
              lrary[j-(r-l)][1,l,r]=max(lrary[j-(r-l)][1,l,r],dpl0[l][r])
            else:
              lrary[j-(r-l)][1,l,r]=dpl0[l][r]
          else:
            ans[l+j]=max(ans[l+j],dpl0[l][r])

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

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