結果

問題 No.1247 ブロック登り
ユーザー chocoruskchocorusk
提出日時 2020-10-04 00:26:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,679 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 135,664 KB
実行使用メモリ 694,656 KB
最終ジャッジ日時 2023-09-25 12:43:11
合計ジャッジ時間 8,660 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
17,724 KB
testcase_01 AC 3 ms
11,540 KB
testcase_02 AC 6 ms
25,896 KB
testcase_03 AC 3 ms
9,624 KB
testcase_04 AC 11 ms
48,500 KB
testcase_05 AC 8 ms
38,340 KB
testcase_06 AC 4 ms
17,672 KB
testcase_07 AC 46 ms
139,696 KB
testcase_08 AC 36 ms
165,764 KB
testcase_09 AC 22 ms
99,812 KB
testcase_10 AC 28 ms
132,676 KB
testcase_11 AC 519 ms
454,760 KB
testcase_12 AC 422 ms
453,244 KB
testcase_13 AC 413 ms
507,056 KB
testcase_14 AC 414 ms
507,044 KB
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 AC 28 ms
116,272 KB
testcase_23 AC 23 ms
100,048 KB
testcase_24 AC 3 ms
9,496 KB
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
ll dp[4][303][303][303];
const ll INF=1e18;
template<typename T>
void chmax(T &x, T y){
    x=max(x, y);
}
int main()
{
    int n, k;
    cin>>n>>k;
    ll a[303];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        for(int j=i; j<n; j++){
            for(int l=0; l<=k; l++){
                for(int t=0; t<4; t++){
                    dp[t][i][j][l]=-INF;
                }
            }
        }
    }
    vector<P> v;
    for(int i=0; i<n; i++) for(int j=i; j<n; j++) v.push_back({i, j});
    sort(v.begin(), v.end(), [&](P a, P b){ return a.second-a.first<b.second-b.first;});
    for(int i=0; i<n; i++){
        dp[0][i][i][k]=a[i]*k;
        dp[1][i][i][k]=a[i]*k;
    }
    for(auto p:v){
        int l=p.first, r=p.second;
        for(int i=k; i>=1; i--){
            if(l<r && i-(r-l)>=0){
                chmax(dp[1][l][r][i-(r-l)], dp[0][l][r][i]);
            }
            if(l<r){
                chmax(dp[2][l][r][i-1], dp[0][l][r][i]);
            }
            if(l-1>=0){
                chmax(dp[0][l-1][r][i-1], dp[0][l][r][i]+a[l-1]*(i-1));
            }
            if(l<r){
                chmax(dp[0][l][r][i-1], dp[2][l][r][i]);
            }
            if(l<r && i-(r-l)>=0){
                chmax(dp[0][l][r][i-(r-l)], dp[1][l][r][i]);
            }
            if(l<r){
                chmax(dp[3][l][r][i-1], dp[1][l][r][i]);
            }
            if(r+1<n){
                chmax(dp[1][l][r+1][i-1], dp[1][l][r][i]+a[r+1]*(i-1));
            }
            if(l<r){
                chmax(dp[1][l][r][i-1], dp[3][l][r][i]);
            }
        }
    }
    ll ans[303];
    fill(ans, ans+n, -INF);
    for(auto p:v){
        int l=p.first, r=p.second;
        if(l==r) continue;
        ll mxl[2]={-INF, -INF}, mxr[2]={-INF, -INF};
        for(int i=k; i>=0; i--){
            chmax(mxl[i&1], dp[0][l][r][i]);
            chmax(mxr[i&1], dp[1][l][r][i]);
            if(i<=r-l){
                chmax(ans[l+i], mxl[i&1]);
                chmax(ans[r-i], mxr[i&1]);
            }
        }
    }
    for(int i=0; i<n; i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}
0