結果

問題 No.1247 ブロック登り
ユーザー chocoruskchocorusk
提出日時 2020-10-04 00:03:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,679 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 136,496 KB
実行使用メモリ 458,408 KB
最終ジャッジ日時 2023-09-25 12:08:48
合計ジャッジ時間 7,236 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
17,764 KB
testcase_01 AC 3 ms
11,540 KB
testcase_02 AC 6 ms
26,024 KB
testcase_03 AC 3 ms
9,540 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 4 ms
17,748 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 22 ms
99,852 KB
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

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[3][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]);
            }
        }
    }
    for(int i=0; i<n; i++){
        ll ans=-INF;
        for(auto p:v){
            int l=p.first, r=p.second;
            if(l==r) continue;
            if(!(l<=i && i<=r)) continue;
            for(int j=0; j<=k; j++){
                if(((i-l)&1)==(j&1) && i-l<=j){
                    chmax(ans, dp[0][l][r][j]);
                }
                if(((r-i)&1)==(j&1) && r-i<=j){
                    chmax(ans, dp[1][l][r][j]);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
0