結果

問題 No.1247 ブロック登り
ユーザー MisterMister
提出日時 2020-11-04 07:08:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,824 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 85,596 KB
実行使用メモリ 814,540 KB
最終ジャッジ日時 2023-09-29 15:34:12
合計ジャッジ時間 5,585 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 19 ms
12,488 KB
testcase_08 AC 21 ms
13,552 KB
testcase_09 AC 6 ms
6,248 KB
testcase_10 AC 7 ms
7,204 KB
testcase_11 MLE -
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 <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int INF = 1 << 30;

void solve() {
    int n, k;
    std::cin >> n >> k;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    auto dp = vec(k, vec(n, vec(n, vec(2, -INF))));
    // h, l, r, side (0 <=> left)

    for (int i = 0; i < n; ++i) {
        for (int s = 0; s < 2; ++s) {
            dp[k - 1][i][i][s] = xs[i] * k;
        }
    }

    for (int h = k - 1; h > 0; --h) {
        for (int l = 0; l < n; ++l) {
            for (int r = l; r < n; ++r) {
                // left
                {
                    auto prev = dp[h][l][r][0];

                    // out
                    if (l - 1 >= 0) {
                        dp[h - 1][l - 1][r][0] = std::max(dp[h - 1][l - 1][r][0],
                                                          prev + xs[l - 1] * h);
                    }

                    // down
                    if (h < r - l) {
                        dp[0][l + h][r][0] = std::max(dp[0][l + h][r][0], prev);
                    }
                }

                // right
                {
                    auto prev = dp[h][l][r][1];

                    // out
                    if (r + 1 < n) {
                        dp[h - 1][l][r + 1][1] = std::max(dp[h - 1][l][r + 1][1],
                                                          prev + xs[r + 1] * h);
                    }

                    // down
                    if (h < r - l) {
                        dp[0][l][r - h][1] = std::max(dp[0][l][r - h][1], prev);
                    }
                }

                for (int s = 0; s < 2; ++s) {
                    auto prev = dp[h][l][r][s];

                    // stay
                    if (r - l >= 1 && h >= 2) {
                        dp[h - 2][l][r][s] = std::max(dp[h - 2][l][r][s], prev);
                    }

                    // move
                    if (r - l >= 1 && h >= r - l) {
                        auto nh = h - (r - l);
                        dp[nh][l][r][1 - s] = std::max(dp[nh][l][r][1 - s], prev);
                    }
                }
            }
        }
    }

    std::vector<int> ans(n, -INF);
    for (int l = 0; l < n; ++l) {
        for (int r = l; r < n; ++r) {
            for (int s = 0; s < 2; ++s) {
                auto i = (s == 0 ? l : r);
                for (int d : {-1, 1}) {
                    if (0 <= i + d && i + d < n) {
                        ans[i + d] = std::max(ans[i + d], dp[0][l][r][s]);
                    }
                }
            }
        }
    }

    for (auto a : ans) std::cout << a << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0