結果

問題 No.1247 ブロック登り
ユーザー 👑 NachiaNachia
提出日時 2020-10-05 17:55:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 702 ms / 3,000 ms
コード長 1,032 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 70,188 KB
実行使用メモリ 216,464 KB
最終ジャッジ日時 2023-09-27 04:10:25
合計ジャッジ時間 10,762 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,440 KB
testcase_01 AC 2 ms
7,528 KB
testcase_02 AC 2 ms
7,520 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3 ms
9,580 KB
testcase_05 AC 4 ms
11,780 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 10 ms
38,636 KB
testcase_08 AC 11 ms
42,636 KB
testcase_09 AC 8 ms
34,276 KB
testcase_10 AC 7 ms
28,212 KB
testcase_11 AC 620 ms
216,348 KB
testcase_12 AC 659 ms
206,704 KB
testcase_13 AC 677 ms
216,464 KB
testcase_14 AC 670 ms
216,456 KB
testcase_15 AC 562 ms
216,408 KB
testcase_16 AC 702 ms
216,420 KB
testcase_17 AC 610 ms
216,412 KB
testcase_18 AC 606 ms
206,192 KB
testcase_19 AC 54 ms
36,132 KB
testcase_20 AC 19 ms
17,652 KB
testcase_21 AC 4 ms
4,736 KB
testcase_22 AC 49 ms
189,768 KB
testcase_23 AC 47 ms
189,316 KB
testcase_24 AC 40 ms
186,208 KB
testcase_25 AC 678 ms
216,344 KB
testcase_26 AC 661 ms
216,420 KB
testcase_27 AC 639 ms
216,368 KB
testcase_28 AC 644 ms
216,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<math.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N,K;
LL A[300];
LL dp[301][301][301];

int main(){
 cin>>N>>K;
 rep(i,N) cin>>A[i];

 rep(i,K+1) rep(l,N+1) rep(r,N+1) dp[i][l][r]=-1000000000000;
 rep(i,N) dp[K][i+1][i]=dp[K][i][i+1]=A[i]*K;

 for(int k=K; k>=1; k--) for(int l=0; l<=N; l++) for(int r=0; r<=N; r++){
  if(k>=2) if(abs(l-r)>=2) dp[k-2][l][r] = max(dp[k-2][l][r],dp[k][l][r]);
  if(l<=r){
   if(r!=N) dp[k-1][l][r+1] = max(dp[k-1][l][r+1],dp[k][l][r]+A[r]*(k-1));
  }
  else{
   if(r!=0) dp[k-1][l][r-1] = max(dp[k-1][l][r-1],dp[k][l][r]+A[r-1]*(k-1));
  }
  if(abs(r-l)>=2) if(k>=abs(r-l)-1)
   dp[k-abs(r-l)+1][r][l] = max(dp[k-abs(r-l)+1][r][l], dp[k][l][r]);
 }

 rep(i,N){
  LL ans=-1000000000000;
  for(int k=0; k<=K; k++){
   if(i+k<N) for(int l=0; l<=i; l++) ans = max(ans,dp[k][l][i+1+k]);
   if(i-k>=0) for(int r=i+1; r<=N; r++) ans = max(ans,dp[k][r][i-k]);
  }
  cout<<ans<<endl;
 }

 return 0;
}
0