結果

問題 No.1077 Noelちゃんと星々4
ユーザー 👑 deuteridayodeuteridayo
提出日時 2020-06-12 22:28:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 169,236 KB
実行使用メモリ 218,212 KB
最終ジャッジ日時 2023-09-06 10:45:01
合計ジャッジ時間 4,335 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,424 KB
testcase_01 AC 3 ms
5,120 KB
testcase_02 AC 129 ms
146,132 KB
testcase_03 AC 169 ms
192,300 KB
testcase_04 AC 49 ms
56,496 KB
testcase_05 AC 38 ms
42,920 KB
testcase_06 AC 67 ms
73,128 KB
testcase_07 AC 75 ms
84,280 KB
testcase_08 AC 54 ms
61,488 KB
testcase_09 AC 46 ms
52,968 KB
testcase_10 AC 170 ms
192,292 KB
testcase_11 AC 109 ms
121,800 KB
testcase_12 AC 89 ms
99,712 KB
testcase_13 AC 36 ms
40,804 KB
testcase_14 AC 167 ms
187,712 KB
testcase_15 AC 84 ms
96,200 KB
testcase_16 AC 55 ms
63,300 KB
testcase_17 AC 97 ms
109,728 KB
testcase_18 AC 171 ms
195,988 KB
testcase_19 AC 34 ms
38,960 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 191 ms
218,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int y[n];
    for(int i=0;i<n;i++){
        cin >> y[i];
    }

    vector<vector<int> >dp(n*5,vector<int>(n+10000,1<<30));
    for(int i=0;i<=10000;i++){
        dp[0][i] = abs(y[0]-i);
    }
    for(int i=1;i<n;i++){
        int minn[40001];
        minn[0] = dp[i-1][0];
        for(int j=1;j<=10000;j++){
            minn[j] = min(minn[j-1],dp[i-1][j]);
        }
        for(int j=0;j<=10000;j++){
            dp[i][j] = minn[j] + abs(y[i]-j);
        }
    }
    int ans = 1<<30;
    for(int i=0;i<=10000;i++){
        ans = min(ans,dp[n-1][i]);
    }
    cout << ans << endl;
}
0