結果

問題 No.952 危険な火薬庫
ユーザー finefine
提出日時 2019-12-15 01:19:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,076 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 170,844 KB
実行使用メモリ 54,168 KB
最終ジャッジ日時 2023-09-10 18:46:11
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll INF = 1e18;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector< vector<ll> > dp(n + 1, vector<ll>(n + 1, INF));
    dp[0][0] = 0;
    {
        ll sum = 0;
        for (int i = 0; i < n; ++i) {
            sum += a[i];
            dp[i + 1][i + 1] = sum * sum;
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (dp[i][j] >= INF) continue;

            int lim = min(n - j, n - 1 - i);
            ll sum = 0;
            for (int k = 1; k <= lim; ++k) {
                sum += a[i + k];
                dp[i + 1 + k][j + k] = min(dp[i + 1 + k][j + k], dp[i][j] + sum * sum);
            }
        }
    }

    for (int k = 1; k <= n; ++k) {
        ll ans = INF;
        for (int i = k; i <= n; ++i) {
            ans = min(ans, dp[i][k]);
        }
        cout << ans << "\n";
    }
    return 0;
}
0