結果

問題 No.1077 Noelちゃんと星々4
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-12 23:37:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 147,976 KB
実行使用メモリ 42,028 KB
最終ジャッジ日時 2023-09-06 11:28:31
合計ジャッジ時間 2,968 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 37 ms
29,900 KB
testcase_03 AC 47 ms
37,836 KB
testcase_04 AC 15 ms
13,512 KB
testcase_05 AC 12 ms
11,028 KB
testcase_06 AC 19 ms
16,760 KB
testcase_07 AC 22 ms
18,624 KB
testcase_08 AC 16 ms
14,356 KB
testcase_09 AC 14 ms
12,800 KB
testcase_10 AC 46 ms
37,880 KB
testcase_11 AC 31 ms
25,476 KB
testcase_12 AC 25 ms
21,516 KB
testcase_13 AC 12 ms
10,372 KB
testcase_14 AC 45 ms
37,032 KB
testcase_15 AC 24 ms
20,964 KB
testcase_16 AC 17 ms
14,852 KB
testcase_17 AC 28 ms
23,500 KB
testcase_18 AC 47 ms
38,616 KB
testcase_19 AC 11 ms
10,124 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 52 ms
42,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.12 23:37:02
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    constexpr int INF = 1e9 + 6;
    vector<vector<int>> dp(n+1,vector<int>(10001,INF));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        int m = INF;
        for (int j = 0; j <= 10000; j++) {
            m = min(m,dp[i][j]);
            dp[i + 1][j] = m + abs(a[i]-j);
        }
    }
    int ans = INF;
    for (int i = 0; i <= 10000; i++) {
        ans = min(ans,dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}
0