結果

問題 No.1077 Noelちゃんと星々4
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-08-26 12:13:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 89,968 KB
実行使用メモリ 81,664 KB
最終ジャッジ日時 2024-04-24 18:20:25
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 57 ms
57,088 KB
testcase_03 AC 72 ms
72,960 KB
testcase_04 AC 24 ms
24,192 KB
testcase_05 AC 18 ms
18,944 KB
testcase_06 AC 30 ms
30,592 KB
testcase_07 AC 35 ms
34,688 KB
testcase_08 AC 25 ms
26,240 KB
testcase_09 AC 22 ms
22,912 KB
testcase_10 AC 72 ms
72,960 KB
testcase_11 AC 50 ms
48,256 KB
testcase_12 AC 40 ms
40,320 KB
testcase_13 AC 17 ms
18,304 KB
testcase_14 AC 71 ms
71,552 KB
testcase_15 AC 39 ms
39,168 KB
testcase_16 AC 26 ms
26,624 KB
testcase_17 AC 44 ms
44,032 KB
testcase_18 AC 77 ms
74,496 KB
testcase_19 AC 17 ms
17,408 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 83 ms
81,664 KB
権限があれば一括ダウンロードができます

ソースコード

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