結果

問題 No.1247 ブロック登り
ユーザー 👑 rin204rin204
提出日時 2022-07-06 22:39:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,498 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 201,736 KB
実行使用メモリ 214,920 KB
最終ジャッジ日時 2023-08-24 22:45:07
合計ジャッジ時間 12,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 16 ms
4,384 KB
testcase_22 AC 6 ms
6,656 KB
testcase_23 AC 5 ms
5,632 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 722 ms
214,580 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

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 - l); 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