結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー | risujiroh |
提出日時 | 2020-06-12 22:55:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 662 bytes |
コンパイル時間 | 1,885 ms |
コンパイル使用メモリ | 194,504 KB |
最終ジャッジ日時 | 2025-01-11 02:52:15 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; }; constexpr int lim = 1e4; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector dp(lim + 1, 0); while (n--) { int a; cin >> a; vector ndp(lim + 1, inf<int>); int mn = inf<int>; for (int y = 0; y <= lim; ++y) { chmin(mn, dp[y]); ndp[y] = abs(y - a) + mn; } swap(dp, ndp); } cout << *min_element(begin(dp), end(dp)) << '\n'; }