結果

問題 No.1247 ブロック登り
ユーザー 👑 NachiaNachia
提出日時 2020-10-05 17:40:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,442 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 71,520 KB
実行使用メモリ 183,976 KB
最終ジャッジ日時 2023-09-27 04:06:57
合計ジャッジ時間 42,111 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include<bits/stdc++.h>
#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;
 }

 cout<<endl<<endl;

 for(int k=K; k>=0; k--){
  cout<<"k="<<k<<endl;
  rep(l,N+1){
   rep(r,N+1){
    if(dp[k][l][r]<-100000000000) cout<<"-INF";
    else cout<<dp[k][l][r];
    cout<<" ";
   }
   cout<<endl;
  }

  cout<<endl;
 }

 return 0;
}
0