結果
問題 |
No.1077 Noelちゃんと星々4
|
ユーザー |
![]() |
提出日時 | 2020-06-16 22:04:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 1,028 bytes |
コンパイル時間 | 2,673 ms |
コンパイル使用メモリ | 193,688 KB |
最終ジャッジ日時 | 2025-01-11 04:44:24 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> #ifdef _DEBUG #include "debug.hpp" #else #define debug(...) #endif #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932; template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; } int dp[1010][10100]; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> y(n); rep(i, n) cin >> y[i]; rep(i, 1010) rep(j, 10100) dp[i][j] = INF; rep(j, 10100) dp[0][j] = 0; rep(i, n) { int mn = INF; rep(j, 10100) { chmin(mn, dp[i][j]); dp[i+1][j] = mn+abs(y[i]-j); } } int ans = INF; rep(i, 10100) chmin(ans, dp[n][i]); cout << ans << '\n'; return 0; }