結果

問題 No.1247 ブロック登り
ユーザー milanis48663220milanis48663220
提出日時 2021-05-20 22:36:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,458 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 121,468 KB
実行使用メモリ 281,200 KB
最終ジャッジ日時 2024-04-18 14:09:05
合計ジャッジ時間 16,128 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 11 ms
11,520 KB
testcase_08 AC 12 ms
11,648 KB
testcase_09 AC 5 ms
6,016 KB
testcase_10 AC 6 ms
7,936 KB
testcase_11 AC 1,177 ms
219,904 KB
testcase_12 AC 1,026 ms
219,776 KB
testcase_13 AC 1,145 ms
220,032 KB
testcase_14 AC 1,101 ms
219,776 KB
testcase_15 AC 1,112 ms
219,904 KB
testcase_16 AC 1,095 ms
220,032 KB
testcase_17 AC 1,084 ms
219,904 KB
testcase_18 AC 989 ms
209,792 KB
testcase_19 AC 265 ms
215,808 KB
testcase_20 AC 175 ms
196,224 KB
testcase_21 WA -
testcase_22 AC 12 ms
7,296 KB
testcase_23 AC 8 ms
6,400 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1,136 ms
220,032 KB
testcase_26 AC 1,094 ms
219,904 KB
testcase_27 AC 1,100 ms
219,904 KB
testcase_28 AC 1,093 ms
219,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
const ll INF = 1e18;

ll dp[305][305][305][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, k; cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int j = k; j >= 0; j--){
        for(int l = 0; l < n; l++){
            for(int r = l+1; r <= n; r++){
                dp[l][r][j][0] = -INF;
                dp[l][r][j][1] = -INF;
            }
        }
    }

    for(int l = 0; l < n; l++){
        dp[l][l+1][k][0] = a[l]*k;
        dp[l][l+1][k][1] = a[l]*k;
    }

    for(int j = k; j > 0; j--){
        // cout << j << endl;
        for(int l = 0; l < n; l++){
            for(int r = l+1; r <= n; r++){
                for(int p = 0; p < 2; p++){
                    // cout << "dp[" << l << "][" << r << "][" << j << "][" << p << "] = " << dp[l][r][j][p] << endl;
                    int cur = (p == 0 ? l : r-1);
                    // とどまる
                    if(j >= 2 && r-l >= 2) chmax(dp[l][r][j-2][p], dp[l][r][j][p]);
                    // l-1に行く
                    int dist = cur-(l-1);
                    if(l > 0 && dist <= j) chmax(dp[l-1][r][j-dist][0], dp[l][r][j][p]+a[l-1]*(j-dist));
                    // rに行く
                    dist = r-cur;
                    if(r < n && dist <= j) chmax(dp[l][r+1][j-dist][1], dp[l][r][j][p]+a[r]*(j-dist));
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        ll ans = -INF;
        for(int l = 0; l <= i; l++){
            for(int r = max(i+1, l+1); r <= n; r++){
                // lから来る
                chmax(ans, dp[l][r][i-l][0]);
                // r-1から来る
                chmax(ans, dp[l][r][(r-1)-i][1]);
            }
        }
        cout << ans << endl;
    }
}
0