結果

問題 No.1247 ブロック登り
ユーザー msm1993msm1993
提出日時 2020-10-23 15:29:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 751 ms / 3,000 ms
コード長 1,032 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 70,912 KB
実行使用メモリ 216,540 KB
最終ジャッジ日時 2023-09-28 15:25:09
合計ジャッジ時間 10,410 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,492 KB
testcase_01 AC 3 ms
7,452 KB
testcase_02 AC 2 ms
7,712 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 3 ms
9,648 KB
testcase_05 AC 4 ms
11,772 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 11 ms
38,640 KB
testcase_08 AC 12 ms
42,932 KB
testcase_09 AC 9 ms
34,292 KB
testcase_10 AC 8 ms
28,292 KB
testcase_11 AC 751 ms
216,480 KB
testcase_12 AC 698 ms
206,560 KB
testcase_13 AC 675 ms
216,452 KB
testcase_14 AC 669 ms
216,384 KB
testcase_15 AC 697 ms
216,400 KB
testcase_16 AC 667 ms
216,404 KB
testcase_17 AC 663 ms
216,400 KB
testcase_18 AC 604 ms
204,368 KB
testcase_19 AC 63 ms
36,228 KB
testcase_20 AC 24 ms
17,740 KB
testcase_21 AC 4 ms
4,836 KB
testcase_22 AC 38 ms
104,936 KB
testcase_23 AC 35 ms
102,852 KB
testcase_24 AC 20 ms
87,020 KB
testcase_25 AC 708 ms
216,464 KB
testcase_26 AC 682 ms
216,540 KB
testcase_27 AC 678 ms
216,464 KB
testcase_28 AC 708 ms
216,400 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