結果

問題 No.1077 Noelちゃんと星々4
ユーザー masutech16masutech16
提出日時 2020-06-12 21:42:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 1,486 ms
コンパイル使用メモリ 168,420 KB
実行使用メモリ 42,124 KB
最終ジャッジ日時 2023-09-06 10:00:28
合計ジャッジ時間 2,958 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 35 ms
29,924 KB
testcase_03 AC 46 ms
37,888 KB
testcase_04 AC 15 ms
13,728 KB
testcase_05 AC 11 ms
10,988 KB
testcase_06 AC 19 ms
16,720 KB
testcase_07 AC 21 ms
18,800 KB
testcase_08 AC 16 ms
14,320 KB
testcase_09 AC 14 ms
12,724 KB
testcase_10 AC 45 ms
37,892 KB
testcase_11 AC 30 ms
25,432 KB
testcase_12 AC 25 ms
21,544 KB
testcase_13 AC 11 ms
10,388 KB
testcase_14 AC 45 ms
37,108 KB
testcase_15 AC 24 ms
21,168 KB
testcase_16 AC 16 ms
14,576 KB
testcase_17 AC 27 ms
23,316 KB
testcase_18 AC 46 ms
38,452 KB
testcase_19 AC 10 ms
10,216 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 51 ms
42,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#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 coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vi y(n);
  REP(i, n) { cin >> y[i]; }
  vector<vi> dp(n + 1, vi(10001, 0));

  FOR(i, 1, n + 1) {
    int cur = dp[i - 1][0];
    REP(j, 10001) {
      chmin(cur, dp[i - 1][j]);
      dp[i][j] = cur + abs(y[i - 1] - j);
    }
  }

  int ans = 1e9;
  REP(j, 10001) { chmin(ans, dp[n][j]); }
  cout << ans << endl;

  return 0;
}
0