結果

問題 No.1077 Noelちゃんと星々4
ユーザー betrue12betrue12
提出日時 2020-06-12 21:31:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 202,692 KB
実行使用メモリ 42,188 KB
最終ジャッジ日時 2023-09-06 09:51:29
合計ジャッジ時間 3,367 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 31 ms
29,916 KB
testcase_03 AC 40 ms
38,012 KB
testcase_04 AC 14 ms
13,684 KB
testcase_05 AC 10 ms
11,088 KB
testcase_06 AC 17 ms
16,452 KB
testcase_07 AC 19 ms
19,028 KB
testcase_08 AC 13 ms
14,396 KB
testcase_09 AC 12 ms
12,844 KB
testcase_10 AC 39 ms
37,860 KB
testcase_11 AC 26 ms
25,460 KB
testcase_12 AC 22 ms
21,440 KB
testcase_13 AC 10 ms
10,516 KB
testcase_14 AC 39 ms
37,056 KB
testcase_15 AC 21 ms
20,996 KB
testcase_16 AC 16 ms
14,788 KB
testcase_17 AC 25 ms
23,496 KB
testcase_18 AC 41 ms
38,420 KB
testcase_19 AC 9 ms
10,096 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 44 ms
42,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void chmin(int& a, int b){
    a = min(a, b);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    vector<vector<int>> dp(N+1, vector<int>(10001, 1e9));
    dp[0][0] = 0;
    for(int i=0; i<N; i++){
        int mn = 1e9;
        for(int j=0; j<=10000; j++){
            chmin(mn, dp[i][j]);
            chmin(dp[i+1][j], mn + abs(j-A[i]));
        }
    }
    int ans = 1e9;
    for(int j=0; j<=10000; j++) chmin(ans, dp[N][j]);
    cout << ans << endl;
    return 0;
}
0