結果

問題 No.1247 ブロック登り
ユーザー 👑 rin204rin204
提出日時 2022-07-06 22:46:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 660 ms / 3,000 ms
コード長 2,497 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 202,812 KB
実行使用メモリ 214,928 KB
最終ジャッジ日時 2023-08-24 22:52:46
合計ジャッジ時間 11,056 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,604 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 660 ms
214,556 KB
testcase_12 AC 597 ms
204,736 KB
testcase_13 AC 634 ms
214,668 KB
testcase_14 AC 649 ms
214,848 KB
testcase_15 AC 656 ms
214,448 KB
testcase_16 AC 655 ms
214,444 KB
testcase_17 AC 642 ms
214,928 KB
testcase_18 AC 570 ms
195,520 KB
testcase_19 AC 65 ms
35,220 KB
testcase_20 AC 29 ms
15,680 KB
testcase_21 AC 16 ms
4,420 KB
testcase_22 AC 7 ms
6,748 KB
testcase_23 AC 5 ms
5,632 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 618 ms
214,788 KB
testcase_26 AC 631 ms
214,840 KB
testcase_27 AC 634 ms
214,444 KB
testcase_28 AC 631 ms
214,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//#include<atcoder/maxflow>
using namespace std;
//using namespace atcoder;
const int inf = 1 << 30;

void solve(){
    int n, K;
    cin >> n >> K;
    vector<int> A(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    vector<int> dp(n * n * (K + 1) * 2, -inf);
    auto f = [&](int i, int j, int k, int l){
        return ((i * n + j) * (K + 1) + k) * 2 + l;
    };
    for(int i = 0; i < n; i++){
        dp[f(i, i, K, 0)] = A[i] * K;
        dp[f(i, i, K, 1)] = A[i] * K;
    }

    for(int x = K; x > 0; x--){
        for(int l = 0; l < n; l++){
            for(int r = l; r < n; r++){
                int p = f(l, r, x, 0);
                if(l != 0){
                    int p2 = f(l - 1, r, x - 1, 0);
                    dp[p2] = max(dp[p2], dp[p] + A[l - 1] * (x - 1));
                }
                if(l != r){
                    if(x >= 2){
                        int p2 = f(l, r, x - 2, 0);
                        dp[p2] = max(dp[p2], dp[p]);
                    }
                    if(x - (r - l) >= 0){
                        int p2 = f(l, r, x - (r - l), 1);
                        dp[p2] = max(dp[p2], dp[p]);
                    }
                }

                p = f(l, r, x, 1);
                if(r != n - 1){
                    int p2 = f(l, r + 1, x - 1, 1);
                    dp[p2] = max(dp[p2], dp[p] + A[r + 1] * (x - 1));
                }
                if(l != r){
                    if(x >= 2){
                        int p2 = f(l, r, x - 2, 1);
                        dp[p2] = max(dp[p2], dp[p]);
                    }
                    if(x - (r - l) >= 0){
                        int p2 = f(l, r, x - (r - l), 0);
                        dp[p2] = max(dp[p2], dp[p]);
                    }
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        int ans = -inf;
        for(int l = 0; l < min(i + 2, n); l++){
            for(int r = max(0, i - 1); r < n; r++){
                if(l > r) continue;
                if(abs(r - i) <= K){
                    int p = f(l, r, abs(r - i), 1);
                    ans = max(ans, dp[p]);
                }
                if(abs(i - l) <= K){
                    int p = f(l, r, abs(i - l), 0);
                    ans = max(ans, dp[p]);
                }
            }
        }
        cout << ans << "\n";
    }
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t;
    t = 1;
    //cin >> t;
    while(t--) solve();
}
    
    


0