結果

問題 No.1247 ブロック登り
ユーザー momoyuumomoyuu
提出日時 2023-09-24 14:32:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,482 ms / 3,000 ms
コード長 2,037 bytes
コンパイル時間 3,658 ms
コンパイル使用メモリ 249,600 KB
実行使用メモリ 444,316 KB
最終ジャッジ日時 2023-09-24 14:32:34
合計ジャッジ時間 21,706 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,540 KB
testcase_01 AC 2 ms
7,424 KB
testcase_02 AC 4 ms
15,656 KB
testcase_03 AC 2 ms
5,060 KB
testcase_04 AC 2 ms
4,996 KB
testcase_05 AC 3 ms
5,120 KB
testcase_06 AC 2 ms
5,060 KB
testcase_07 AC 16 ms
19,240 KB
testcase_08 AC 16 ms
19,488 KB
testcase_09 AC 6 ms
8,832 KB
testcase_10 AC 9 ms
12,788 KB
testcase_11 AC 1,389 ms
442,244 KB
testcase_12 AC 1,389 ms
443,112 KB
testcase_13 AC 1,428 ms
444,028 KB
testcase_14 AC 1,482 ms
444,100 KB
testcase_15 AC 1,357 ms
444,024 KB
testcase_16 AC 1,461 ms
444,316 KB
testcase_17 AC 1,248 ms
444,028 KB
testcase_18 AC 1,240 ms
426,184 KB
testcase_19 AC 370 ms
443,080 KB
testcase_20 AC 221 ms
443,156 KB
testcase_21 AC 141 ms
442,972 KB
testcase_22 AC 19 ms
61,004 KB
testcase_23 AC 17 ms
54,760 KB
testcase_24 AC 2 ms
7,548 KB
testcase_25 AC 1,294 ms
444,096 KB
testcase_26 AC 1,230 ms
444,312 KB
testcase_27 AC 1,201 ms
444,076 KB
testcase_28 AC 1,213 ms
443,900 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