結果
| 問題 | 
                            No.1077 Noelちゃんと星々4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-06-12 21:50:12 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 198 ms / 2,000 ms | 
| コード長 | 1,067 bytes | 
| コンパイル時間 | 1,744 ms | 
| コンパイル使用メモリ | 172,248 KB | 
| 実行使用メモリ | 163,712 KB | 
| 最終ジャッジ日時 | 2024-06-24 04:50:53 | 
| 合計ジャッジ時間 | 4,499 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
constexpr int H = 20000;
int main() {
    int N; cin >> N;
    vector<ll> Y(N);
    rep(i,N) cin >> Y[i];
    
    vector<vector<ll>> dp(N + 1,vector<ll>(H,INF));
    rep(i,N) {
        if (i == 0) {
            rep(j,H) {
                if (j == 0) dp[i + 1][j] = abs(j - Y[i]);
                else dp[i + 1][j] = min(dp[i + 1][j - 1],abs(j - Y[i]));
            }
        }
        else {
            rep(j,H) {
                if (j == 0) dp[i + 1][j] = dp[i][j] + abs(j - Y[i]);
                else dp[i + 1][j] = min(dp[i + 1][j - 1],dp[i][j] + abs(j - Y[i]));
            }
        }
    }
    
    ll ans = HINF;
    rep(i,H) {
        ans = min(ans,dp[N][i]);
    }
    cout << ans << endl;
    return 0;
}