結果

問題 No.1247 ブロック登り
ユーザー 👑 hitonanodehitonanode
提出日時 2020-10-03 13:49:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 3,000 ms
コード長 2,009 bytes
コンパイル時間 8,436 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 215,148 KB
最終ジャッジ日時 2023-09-25 05:11:29
合計ジャッジ時間 15,960 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,680 KB
testcase_01 AC 3 ms
9,588 KB
testcase_02 AC 3 ms
11,628 KB
testcase_03 AC 2 ms
5,488 KB
testcase_04 AC 3 ms
11,784 KB
testcase_05 AC 4 ms
13,752 KB
testcase_06 AC 3 ms
5,532 KB
testcase_07 AC 10 ms
40,596 KB
testcase_08 AC 11 ms
44,740 KB
testcase_09 AC 8 ms
34,312 KB
testcase_10 AC 7 ms
32,132 KB
testcase_11 AC 291 ms
215,108 KB
testcase_12 AC 265 ms
205,556 KB
testcase_13 AC 281 ms
215,140 KB
testcase_14 AC 284 ms
215,112 KB
testcase_15 AC 293 ms
215,084 KB
testcase_16 AC 323 ms
215,080 KB
testcase_17 AC 290 ms
215,128 KB
testcase_18 AC 258 ms
205,868 KB
testcase_19 AC 31 ms
39,188 KB
testcase_20 AC 12 ms
18,532 KB
testcase_21 AC 4 ms
8,164 KB
testcase_22 AC 39 ms
140,452 KB
testcase_23 AC 36 ms
138,984 KB
testcase_24 AC 27 ms
129,736 KB
testcase_25 AC 289 ms
215,056 KB
testcase_26 AC 281 ms
215,084 KB
testcase_27 AC 327 ms
215,084 KB
testcase_28 AC 287 ms
215,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3")
// #pragma GCC target("avx")
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
template <typename T>
bool chmax(T& m, const T q) { return m < q ? (m = q, true) : false; }


int main()
{
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto &x : A) cin >> x;

    constexpr int INF = 2e9;
    // vector dpl(K + 1, vector(N, vector(N, -INF)));
    // vector dpr(K + 1, vector(N, vector(N, -INF)));
    int dpl[301][300][300];
    int dpr[301][300][300];
    // array<array<array<int, 300>, 300>, 301> dpl;
    // array<array<array<int, 300>, 300>, 301> dpr;
    REP(k, K + 1) REP(i, N) REP(j, N) dpl[k][i][j] = dpr[k][i][j] = -INF;
    REP(i, N) dpl[K][i][i] = dpr[K][i][i] = A[i] * K;

    IFOR(k, 1, K + 1)
    {
        REP(l, N) FOR(r, l, N)
        {
            if (l < r and k > 1)
            {
                chmax(dpl[k - 2][l][r], dpl[k][l][r]);
                chmax(dpr[k - 2][l][r], dpr[k][l][r]);
            }
            if (l) chmax(dpl[k - 1][l - 1][r], dpl[k][l][r] + A[l - 1] * (k - 1));
            if (r + 1 < N) chmax(dpr[k - 1][l][r + 1], dpr[k][l][r] + A[r + 1] * (k - 1));

            if (k - (r - l) >= 0) chmax(dpr[k - (r - l)][l][r], dpl[k][l][r]);
            if (k - (r - l) >= 0) chmax(dpl[k - (r - l)][l][r], dpr[k][l][r]);
        }
    }

    IFOR(k, 1, K + 1)
    {
        REP(l, N) FOR(r, l + 1, N)
        {
            chmax(dpl[k - 1][l + 1][r], dpl[k][l][r]);
            chmax(dpr[k - 1][l][r - 1], dpr[k][l][r]);
        }
    }
    REP(i, N)
    {
        int ret = -INF;
        REP(j, N)
        {
            if (j <= i) chmax(ret, dpr[0][j][i]);
            if (i <= j) chmax(ret, dpl[0][i][j]);
        }
        cout << ret << '\n';
    }
}
0