結果

問題 No.1077 Noelちゃんと星々4
ユーザー hanbei_dayo
提出日時 2020-08-26 12:13:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 89,648 KB
実行使用メモリ 81,792 KB
最終ジャッジ日時 2024-11-07 03:09:03
合計ジャッジ時間 2,449 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

const int MH = 10010;

int main(void){
    int n;
    cin>>n;

    vector<ll>Y(n);
    for(int i=0;i<n;i++)cin>>Y[i];
    vector<vector<ll>>dp(n+1,vector<ll>(MH,INF));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        vector<ll>a(MH,INF);
        a[0] = dp[i][0];
        for(ll j=1;j<MH;j++)a[j] = min(a[j-1],dp[i][j]);
        for(ll j=0;j<MH;j++){
            ll cost = a[j]+abs(Y[i]-j);
            dp[i+1][j] = min(dp[i+1][j],cost);
        }
    }
    cout<<*min_element(dp[n].begin(),dp[n].end())<<endl;
}

0