結果
問題 | No.952 危険な火薬庫 |
ユーザー |
![]() |
提出日時 | 2021-12-12 10:46:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,356 bytes |
コンパイル時間 | 3,935 ms |
コンパイル使用メモリ | 252,184 KB |
最終ジャッジ日時 | 2025-01-26 09:01:00 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 5 TLE * 13 |
ソースコード
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; #define rep(a,n) for(ll a = 0;a < n;a++) template<typename T> static inline void chmin(T& ref, const T value) { if (ref > value) ref = value; } template<typename T> static inline void chmax(T& ref, const T value) { if (ref < value) ref = value; } #include <atcoder/all> using namespace atcoder; typedef modint998244353 mint; mint mpow(mint x, ll n) { mint ans = 1; while (n != 0) { if (n & 1) ans = ans * x; x = x * x; n = n >> 1; } return ans; } int main() { ll n; cin >> n; vector<ll> as(n); rep(i, n) cin >> as[i]; vector<ll> ss(n + 1, 0); rep(i, n) ss[i + 1] = ss[i] + as[i]; //dp[i][j]...dp[i-1][j-1] vector<vector<ll>> dp(n + 2, vector<ll>(n + 1, 1e15)); dp[0][0] = 0; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n + 1; j++) { ll lower = 1e15; for (int k = 0; k <= i; k++) { if (i - k < 0) continue; if (j - k < 0) continue; ll s = ss[i] - ss[i - k]; chmin(lower, dp[i - k][j - k] + s * s); } dp[i + 1][j] = lower; } } for (int k = 1; k <= n; k++) { cout << dp[n + 1][k] << endl; } return 0; }