結果

問題 No.1077 Noelちゃんと星々4
ユーザー IKyoproIKyopro
提出日時 2020-06-12 21:26:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 203,212 KB
実行使用メモリ 42,592 KB
最終ジャッジ日時 2023-09-06 09:45:21
合計ジャッジ時間 3,462 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 30 ms
30,180 KB
testcase_03 AC 40 ms
37,804 KB
testcase_04 AC 13 ms
13,644 KB
testcase_05 AC 10 ms
10,876 KB
testcase_06 AC 17 ms
16,816 KB
testcase_07 AC 19 ms
18,952 KB
testcase_08 AC 14 ms
14,336 KB
testcase_09 AC 12 ms
12,788 KB
testcase_10 AC 40 ms
37,856 KB
testcase_11 AC 26 ms
25,428 KB
testcase_12 AC 22 ms
21,560 KB
testcase_13 AC 10 ms
10,452 KB
testcase_14 AC 40 ms
37,100 KB
testcase_15 AC 22 ms
20,948 KB
testcase_16 AC 15 ms
14,612 KB
testcase_17 AC 24 ms
23,444 KB
testcase_18 AC 42 ms
38,348 KB
testcase_19 AC 9 ms
10,212 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 46 ms
42,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N);
    for(auto& x:A) cin >> x;
    int inf = 1e9;
    int M = 1e4;
    vvec<int> dp(N+1,vec<int>(M+1,inf));
    dp[0][0] = 0;
    for(int i=0;i<N;i++){
        int mi = inf;
        for(int j=0;j<=M;j++){
            mi = min(mi,dp[i][j]);
            dp[i+1][j] = min(dp[i+1][j],mi+abs(A[i]-j));
        }
    }
    cout << *min_element(dp[N].begin(),dp[N].end()) << "\n";
}
0