結果

問題 No.1077 Noelちゃんと星々4
ユーザー kappybarkappybar
提出日時 2020-06-12 21:36:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 169,340 KB
実行使用メモリ 81,452 KB
最終ジャッジ日時 2023-09-06 09:55:52
合計ジャッジ時間 3,279 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 54 ms
56,636 KB
testcase_03 AC 66 ms
72,736 KB
testcase_04 AC 22 ms
23,900 KB
testcase_05 AC 16 ms
18,576 KB
testcase_06 AC 27 ms
30,352 KB
testcase_07 AC 31 ms
34,468 KB
testcase_08 AC 23 ms
25,756 KB
testcase_09 AC 20 ms
22,696 KB
testcase_10 AC 68 ms
72,752 KB
testcase_11 AC 44 ms
48,128 KB
testcase_12 AC 36 ms
40,148 KB
testcase_13 AC 16 ms
18,084 KB
testcase_14 AC 67 ms
71,152 KB
testcase_15 AC 35 ms
38,888 KB
testcase_16 AC 24 ms
26,612 KB
testcase_17 AC 40 ms
43,648 KB
testcase_18 AC 69 ms
74,060 KB
testcase_19 AC 15 ms
17,288 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 76 ms
81,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
const ll MX = 10005;

int main(){
    ll n;
    cin >> n;
    vector<ll> y(n);
    rep(i,n) cin >> y[i];
    vector<vector<ll>> dp(n+1,vector<ll>(MX,0));
    for(ll i=1;i<=n;i++){
        ll mn = INF;
        rep(j,MX){
            mn = min(mn,dp[i-1][j]);
            dp[i][j] = mn + abs(y[i-1] - j);
        }
    }

    ll ans = INF;
    rep(j,MX){
        ans = min(ans,dp[n][j]);
    }
    cout << ans << endl;
    return 0;
}
0