結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
![]() |
提出日時 | 2020-07-24 13:45:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 1,079 bytes |
コンパイル時間 | 2,070 ms |
コンパイル使用メモリ | 199,460 KB |
最終ジャッジ日時 | 2025-01-12 04:56:47 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>#define M_PI 3.14159265358979323846 // piusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef vector<ll> VI;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++)#define repi(a,b,n) for(ll a = b;a < n;a++)using namespace std;static const ll INF = 1e15;const ll mod = 1000000007;template<typename T>void chmin(T & ref, const T value) {if (ref > value) ref = value;}int main() {int n;cin >> n;vector<ll> vs(n);rep(i, n) cin >> vs[i];vector<vector<ll>> dp(n + 1, vector<ll>(1e4 + 1, INF));dp[0][0] = 0;rep(i, n) {const ll v = vs[i];vector<ll> lows = dp[i];rep(j, 1e4) {lows[j + 1] = min(lows[j + 1], lows[j]);}rep(j, 1e4 + 1) {if (j <= v) {chmin(dp[i + 1][j], lows[j] + v- j );}else {chmin(dp[i + 1][j], dp[i][j] + j - v);}}}ll low = INF;rep(j, 1e4 + 1) {chmin(low, dp[n][j]);}cout << low << endl;return 0;}