結果

問題 No.1247 ブロック登り
ユーザー momoyuumomoyuu
提出日時 2023-09-24 14:31:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,036 bytes
コンパイル時間 4,874 ms
コンパイル使用メモリ 249,312 KB
実行使用メモリ 456,148 KB
最終ジャッジ日時 2023-09-24 14:32:05
合計ジャッジ時間 17,153 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,584 KB
testcase_01 AC 2 ms
7,468 KB
testcase_02 AC 4 ms
15,604 KB
testcase_03 AC 2 ms
7,372 KB
testcase_04 WA -
testcase_05 AC 5 ms
21,808 KB
testcase_06 AC 3 ms
9,440 KB
testcase_07 WA -
testcase_08 AC 21 ms
79,608 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1,047 ms
444,592 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 739 ms
450,072 KB
testcase_17 WA -
testcase_18 AC 671 ms
436,436 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 99 ms
449,288 KB
testcase_22 AC 16 ms
60,928 KB
testcase_23 AC 13 ms
54,748 KB
testcase_24 AC 2 ms
7,464 KB
testcase_25 AC 737 ms
449,968 KB
testcase_26 AC 751 ms
449,856 KB
testcase_27 AC 747 ms
449,972 KB
testcase_28 AC 729 ms
450,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;


ll dp[2][310][310][310];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    vector<ll> ans(n,-1e18);
    for(int i = 0;i<2;i++) for(int j = 0;j<n;j++) for(int l = 0;l<n;l++) for(int p = 0;p<=k;p++) dp[i][j][l][p] = -1e18;
    for(int i = 0;i<n;i++){
        dp[0][i][i][k-1] = a[i] * k;
        dp[1][i][i][k-1] = a[i] * k;
    }
    for(int i = k;i>=0;i--){
        for(int j = 0;j<n;j++){
            for(int l = j;l<n;l++){
                if(j+1<=l){
                    if(i-2>0){
                        dp[0][j][l][i-2] = max(dp[0][j][l][i-2],dp[0][j][l][i]);
                        dp[1][j][l][i-2] = max(dp[1][j][l][i-2],dp[1][j][l][i]);
                    }
                    if(i%2==1){
                        ans[l] = max(ans[l],dp[0][j][l][i]);
                        ans[j] = max(ans[j],dp[1][j][l][i]);
                    }
                }
                if(i==0){
                    if(l+1<n) ans[l+1] = max(ans[l+1],dp[0][j][l][i]);
                    if(j-1>=0) ans[j-1] = max(ans[j-1],dp[1][j][l][i]);
                }
                if(l+1<n){
                    dp[0][j][l+1][i-1] = max(dp[0][j][l+1][i-1],dp[0][j][l][i]+i*a[l+1]);
                }
                if(j-1>=0){
                    dp[1][j-1][l][i-1] = max(dp[1][j-1][l][i-1],dp[1][j][l][i]+i*a[j-1]);
                }
                int need = l - j;
                if(i-need>=0){
                    dp[0][j][l][i-need] = max(dp[0][j][l][i-need],dp[1][j][l][i]);
                    dp[1][j][l][i-need] = max(dp[1][j][l][i-need],dp[0][j][l][i]);
                }
                int res = i + 1;
                if(j+res<n&&j+res<=l+1) ans[j+res] = max(ans[j+res],dp[1][j][l][i]);
                if(l-res>=0&&l-res>=j-1) ans[l-res] = max(ans[l-res],dp[0][j][l][i]);
            }
        }
    }
    for(int i = 0;i<n;i++) cout<<ans[i]<<endl;
    
}

0