結果

問題 No.1077 Noelちゃんと星々4
ユーザー tsugutsugutsugutsugu
提出日時 2023-06-19 00:23:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 3,466 ms
コンパイル使用メモリ 247,560 KB
実行使用メモリ 42,044 KB
最終ジャッジ日時 2023-09-08 17:59:30
合計ジャッジ時間 4,381 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 34 ms
29,928 KB
testcase_03 AC 44 ms
37,820 KB
testcase_04 AC 14 ms
13,564 KB
testcase_05 AC 11 ms
11,016 KB
testcase_06 AC 17 ms
16,796 KB
testcase_07 AC 20 ms
18,884 KB
testcase_08 AC 15 ms
14,348 KB
testcase_09 AC 13 ms
12,776 KB
testcase_10 AC 43 ms
37,900 KB
testcase_11 AC 28 ms
25,400 KB
testcase_12 AC 24 ms
21,548 KB
testcase_13 AC 11 ms
10,348 KB
testcase_14 AC 43 ms
37,156 KB
testcase_15 AC 23 ms
21,048 KB
testcase_16 AC 15 ms
15,100 KB
testcase_17 AC 26 ms
23,428 KB
testcase_18 AC 44 ms
38,336 KB
testcase_19 AC 11 ms
10,236 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 48 ms
42,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...) 1
#endif

const int mxY = 10005;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(mxY, -(1 << 30)));
    fill(dp[0].begin(), dp[0].end(), 0);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < mxY; j++) {
            dp[i + 1][j] = dp[i][j] + abs(j - a[i]);
        }
        for (int j = 1; j < mxY; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - 1]);
        }
    }
    cout << dp[n][mxY - 1] << '\n';
}
0