結果

問題 No.1077 Noelちゃんと星々4
ユーザー rokahikou1rokahikou1
提出日時 2020-08-18 02:54:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 990 ms
コンパイル使用メモリ 99,184 KB
実行使用メモリ 81,664 KB
最終ジャッジ日時 2024-04-19 19:32:19
合計ジャッジ時間 2,404 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 54 ms
56,960 KB
testcase_03 AC 69 ms
72,832 KB
testcase_04 AC 20 ms
24,192 KB
testcase_05 AC 16 ms
18,944 KB
testcase_06 AC 26 ms
30,592 KB
testcase_07 AC 30 ms
34,688 KB
testcase_08 AC 22 ms
25,984 KB
testcase_09 AC 18 ms
22,784 KB
testcase_10 AC 68 ms
72,960 KB
testcase_11 AC 44 ms
48,128 KB
testcase_12 AC 36 ms
40,320 KB
testcase_13 AC 14 ms
18,176 KB
testcase_14 AC 68 ms
71,168 KB
testcase_15 AC 35 ms
39,168 KB
testcase_16 AC 23 ms
26,496 KB
testcase_17 AC 40 ms
43,904 KB
testcase_18 AC 71 ms
74,112 KB
testcase_19 AC 15 ms
17,280 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 78 ms
81,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int N;
    cin >> N;
    vector<int> Y(N);
    rep(i, N) cin >> Y[i];
    auto dp = make_vec<ll>(N + 1, 10001);
    rep(i, N + 1) { rep(j, 10001) dp[i][j] = LINF; }
    dp[0][0] = 0;
    // dp[i][j]:=i-1個目まで見て、高さjの時の最小コスト
    for(int i = 0; i < N; i++) {
        ll mi = LINF;
        for(int j = 0; j < 10001; j++) {
            mi = min(mi, dp[i][j]);
            dp[i + 1][j] = min(dp[i + 1][j], mi + llabs(Y[i] - j));
        }
    }
    ll res = LINF;
    rep(i, 10001) { res = min(dp[N][i], res); }
    cout << res << endl;
    return 0;
}
0