結果

問題 No.1077 Noelちゃんと星々4
ユーザー knshnbknshnb
提出日時 2020-06-12 21:31:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 204,412 KB
実行使用メモリ 81,492 KB
最終ジャッジ日時 2023-09-06 09:52:07
合計ジャッジ時間 3,750 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 53 ms
56,564 KB
testcase_03 AC 68 ms
72,652 KB
testcase_04 AC 22 ms
23,868 KB
testcase_05 AC 17 ms
18,820 KB
testcase_06 AC 28 ms
30,256 KB
testcase_07 AC 32 ms
34,532 KB
testcase_08 AC 24 ms
26,172 KB
testcase_09 AC 20 ms
22,620 KB
testcase_10 AC 68 ms
72,764 KB
testcase_11 AC 44 ms
48,120 KB
testcase_12 AC 37 ms
40,004 KB
testcase_13 AC 16 ms
18,012 KB
testcase_14 AC 68 ms
71,156 KB
testcase_15 AC 35 ms
39,128 KB
testcase_16 AC 24 ms
26,448 KB
testcase_17 AC 40 ms
43,720 KB
testcase_18 AC 69 ms
73,980 KB
testcase_19 AC 15 ms
17,220 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 77 ms
81,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri Jun 12 21:22:41 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }

const Int Y = (Int)1e4 + 1;
signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    auto dp = make_vec<Int>(n + 1, Y, 0);
    REP(i, n) {
        REP(j, Y) {
            dp[i + 1][j] = dp[i][j] + std::abs(a[i] - j);
            if (j) chmin(dp[i + 1][j], dp[i + 1][j - 1]);
        }
    }
    std::cout << dp[n][Y - 1] << std::endl;
}
0