結果

問題 No.1077 Noelちゃんと星々4
ユーザー wattaiheiwattaihei
提出日時 2020-06-12 23:32:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 980 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 166,132 KB
実行使用メモリ 81,504 KB
最終ジャッジ日時 2023-09-06 11:27:44
合計ジャッジ時間 3,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,492 KB
testcase_02 AC 28 ms
58,620 KB
testcase_03 AC 35 ms
72,960 KB
testcase_04 AC 12 ms
25,780 KB
testcase_05 AC 10 ms
19,696 KB
testcase_06 AC 16 ms
32,020 KB
testcase_07 AC 17 ms
36,104 KB
testcase_08 AC 13 ms
27,856 KB
testcase_09 AC 12 ms
23,772 KB
testcase_10 AC 35 ms
72,920 KB
testcase_11 AC 23 ms
48,412 KB
testcase_12 AC 20 ms
42,200 KB
testcase_13 AC 10 ms
19,668 KB
testcase_14 AC 34 ms
72,920 KB
testcase_15 AC 19 ms
40,148 KB
testcase_16 AC 14 ms
27,828 KB
testcase_17 AC 21 ms
44,380 KB
testcase_18 AC 35 ms
74,940 KB
testcase_19 AC 9 ms
17,616 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 38 ms
81,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
using namespace std;

const int MAX = 10003;
ll INF = 10000000000;
ll dp[1002][MAX+1];

int main() {
    int N; cin >> N;
    ll A[N+1];
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    for (int i=0; i<N+1; i++){
        for (int j=0; j<MAX+1; j++){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0ll;
    for (int i=0; i<N; i++){
        int a = A[i];
        ll k = INF;
        for (int j=0; j<MAX+1; j++){
            k = min(k, dp[i][j]);
            if (j < a){
                dp[i+1][j] = min(dp[i+1][j], k + (ll)(a-j));
            } else {
                dp[i+1][j] = min(dp[i+1][j], k + (ll)(j-a));
            }
        }
    }
    ll ans = INF;
    for (int j=0; j<MAX+1; j++){
        ans = min(ans, dp[N][j]);
        //cout << dp[N][j] << endl;
    }
    cout << ans << endl;


}
0