結果

問題 No.1247 ブロック登り
ユーザー 👑 NachiaNachia
提出日時 2020-10-05 17:42:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,184 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 70,864 KB
実行使用メモリ 216,560 KB
最終ジャッジ日時 2023-09-27 04:08:05
合計ジャッジ時間 11,482 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
7,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 4 ms
4,672 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 13 ms
54,416 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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));
   if(l!=0) dp[k-1][r][l-1] = max(dp[k-1][r][l-1],dp[k][l][r]+A[l-1]*(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(l!=N) dp[k-1][r][l+1] = max(dp[k-1][r][l+1],dp[k][l][r]+A[l]*(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