結果

問題 No.952 危険な火薬庫
ユーザー risujirohrisujiroh
提出日時 2019-12-15 00:11:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 904 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 172,312 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2023-09-10 12:45:44
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 2 ms
4,380 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 13 ms
4,376 KB
testcase_24 AC 361 ms
7,040 KB
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  assert(n <= 600);
  vector<long long> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  vector<long long> cum(n + 1);
  for (int i = n; i--; ) {
    cum[i] = a[i] + cum[i + 1];
  }
  auto chmin = [](auto&& l, auto r) { l = min(l, r); };
  vector< vector<long long> > dp(n + 1, vector<long long>(n + 1, 1e18));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    vector< vector<long long> > ndp(n + 1, vector<long long>(n + 1, 1e18));
    for (int k = 0; k <= i; ++k) {
      for (int x = 0; x <= k; ++x) {
        chmin(ndp[k][0], dp[k][x]);
        chmin(ndp[k + 1][x + 1], dp[k][x] + a[i] * a[i] + 2 * a[i] * (cum[i - x] - cum[i]));
      }
    }
    swap(dp, ndp);
  }
  for (int k = 1; k <= n; ++k) {
    cout << *min_element(begin(dp[k]), end(dp[k])) << '\n';
  }
}
0