結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー |
![]() |
提出日時 | 2020-06-14 19:08:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 1,408 bytes |
コンパイル時間 | 2,465 ms |
コンパイル使用メモリ | 196,960 KB |
最終ジャッジ日時 | 2025-01-11 04:16:44 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> #define rep(i, a, b) for(int i = a; i < b; i++) #define Rep(i, a, b) for(int i = a; i <= b; i++) #define repr(i, a, b) for(int i = a; i >= b; i--) #define _GLIBCXX_DEBUG #define Vl vector<ll> #define Vs vector<string> #define Vp vector<pair<ll, ll>> #define ld long double using ll = long long; #define ALL(v) (v).begin(),(v).end() #define endl "\n" #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define co(x) cout << x << endl #define coel cout << endl #define pb push_back #define sz(v) ((ll)(v).size()) using namespace std; const double pi = acos(-1.0); const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; #define pp pair<ll, pair<ll, ll>> #define fi first #define se second void print(Vl vec){ rep(i, 0, sz(vec)){ if(i) cout << " "; cout << vec[i]; } coel; } //////////////////////////////////////////////////////// // デバッグを消し忘れるな!!! const ll mx = 10005; int main() { ll n; cin >> n; Vl y(n+1); Rep(i, 1, n) cin >> y[i]; vector<Vl> dp(n+1, Vl(mx, INF)); rep(i, 0, mx){ dp[1][i] = llabs(i-y[1]); } Rep(i, 2, n){ ll M = INF; rep(j, 0, mx){ chmin(M, dp[i-1][j]); chmin(dp[i][j], M + llabs(y[i] - j)); } } ll ans = INF; rep(i, 0, mx){ chmin(ans, dp[n][i]); } co(ans); return 0; }