結果

問題 No.952 危険な火薬庫
ユーザー Shuz*Shuz*
提出日時 2019-12-16 20:46:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 775 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 64,656 KB
実行使用メモリ 53,980 KB
最終ジャッジ日時 2023-09-15 18:29:51
合計ジャッジ時間 4,042 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,380 KB
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 <iostream>
using namespace std;
using ll = long long;
const ll INF = 1e18;

int main() {
    int N;
    cin >> N;
    ll S[N + 1], DP[N + 2][N + 1];
    S[0] = 0;
    for (int i = 0; i < N; i++) cin >> S[i + 1], S[i + 1] += S[i];
    for (int i = 0; i < N + 2; i++) {
        for (int j = 0; j < N + 1; j++) DP[i][j] = INF;
    }
    DP[0][0] = 0;
    for (int i = 0; i < N + 1; i++) {
        for (int j = 0; j < N + 1; j++) {
            for (int k = 0; k < N + 2; k++) {
                if (i - k < 0 || j - k < 0) continue;
                ll cost = S[i] - S[i - k];
                DP[i + 1][j] = min(DP[i + 1][j], DP[i - k][j - k] + cost * cost);
            }
        }
    }
    for (int i = 0; i < N; i++) {
        cout << DP[N + 1][i + 1] << endl;
    }
}
0