結果

問題 No.952 危険な火薬庫
ユーザー square1001square1001
提出日時 2020-01-31 19:53:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 802 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 73,900 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 08:27:08
合計ジャッジ時間 6,022 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 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 <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 60;
int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<long long> S(N + 1);
	for (int i = 0; i < N; ++i) {
		S[i + 1] = S[i] + A[i];
	}
	vector<long long> dp(N + 1, inf);
	dp[0] = 0;
	vector<long long> ans(N + 1, inf);
	for (int i = N; i >= 1; --i) {
		for (int j = 0; j <= N; ++j) {
			ans[i] = min(ans[i], dp[j] + (S[N] - S[j]) * (S[N] - S[j]));
		}
		vector<long long> ndp(N + 1, inf);
		for (int j = 0; j <= N; ++j) {
			for (int k = j - 1; k >= 0; --k) {
				ndp[j] = min(ndp[j], dp[k] + (S[j - 1] - S[k]) * (S[j - 1] - S[k]));
			}
		}
		dp = ndp;
	}
	for (int i = 1; i <= N; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}
0