結果

問題 No.1077 Noelちゃんと星々4
ユーザー onsen_manjuuuonsen_manjuuu
提出日時 2020-06-13 01:51:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 169,804 KB
実行使用メモリ 42,156 KB
最終ジャッジ日時 2023-09-06 11:40:02
合計ジャッジ時間 2,860 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 39 ms
30,036 KB
testcase_03 AC 50 ms
37,924 KB
testcase_04 AC 16 ms
13,572 KB
testcase_05 AC 12 ms
11,060 KB
testcase_06 AC 19 ms
16,420 KB
testcase_07 AC 22 ms
18,924 KB
testcase_08 AC 17 ms
14,312 KB
testcase_09 AC 15 ms
13,024 KB
testcase_10 AC 50 ms
37,808 KB
testcase_11 AC 33 ms
25,440 KB
testcase_12 AC 27 ms
21,480 KB
testcase_13 AC 12 ms
10,488 KB
testcase_14 AC 49 ms
37,336 KB
testcase_15 AC 26 ms
20,944 KB
testcase_16 AC 18 ms
14,576 KB
testcase_17 AC 30 ms
23,340 KB
testcase_18 AC 51 ms
38,376 KB
testcase_19 AC 11 ms
10,088 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 57 ms
42,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int high = 1e4+1;

int main()
{
    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>(high, INF)); //dp[i][j] := a[i]の段差j以下に行くときの最小コスト
    for(int i = 0; i < high; i++)dp[0][i] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < high; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], abs(a[i] - j) + dp[i][j]);
            if(j != 0)dp[i + 1][j] = min(dp[i + 1][j - 1], dp[i + 1][j]);
        }
    }
    cout << dp[n][high-1] << endl;
}
0