結果

問題 No.1077 Noelちゃんと星々4
ユーザー milanis48663220milanis48663220
提出日時 2020-06-14 01:20:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 42,428 KB
最終ジャッジ日時 2023-09-08 11:10:29
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 24 ms
32,016 KB
testcase_03 AC 29 ms
38,272 KB
testcase_04 AC 11 ms
15,664 KB
testcase_05 AC 9 ms
11,560 KB
testcase_06 AC 13 ms
17,716 KB
testcase_07 AC 15 ms
19,692 KB
testcase_08 AC 11 ms
15,608 KB
testcase_09 AC 10 ms
13,672 KB
testcase_10 AC 30 ms
38,116 KB
testcase_11 AC 21 ms
25,904 KB
testcase_12 AC 18 ms
23,776 KB
testcase_13 AC 8 ms
11,652 KB
testcase_14 AC 29 ms
38,156 KB
testcase_15 AC 17 ms
21,736 KB
testcase_16 AC 11 ms
15,604 KB
testcase_17 AC 18 ms
23,852 KB
testcase_18 AC 31 ms
40,204 KB
testcase_19 AC 9 ms
11,504 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 33 ms
42,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N;
int Y[1000];
int dp[1001][10001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> Y[i];
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= 10000; j++){
            dp[i+1][j] = dp[i][j]+abs(Y[i]-j);
            if(j > 0) dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-1]);
        }
    }
    int ans = 1e9;
    for(int i = 0; i <= 10000; i++) ans = min(ans, dp[N][i]);
    cout << ans << endl;
}
0