結果

問題 No.1077 Noelちゃんと星々4
ユーザー wattaiheiwattaihei
提出日時 2020-06-12 23:30:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 980 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 198,796 KB
実行使用メモリ 83,128 KB
最終ジャッジ日時 2023-09-06 11:26:36
合計ジャッジ時間 7,981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,492 KB
testcase_01 AC 8 ms
13,576 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 3 ms
5,052 KB
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = 100000;
ll INF = 10000000000;
ll dp[102][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