結果

問題 No.1077 Noelちゃんと星々4
ユーザー hipotafhipotaf
提出日時 2020-06-12 23:43:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,178 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 77,436 KB
実行使用メモリ 81,664 KB
最終ジャッジ日時 2024-06-24 06:06:01
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <cmath>

using namespace std;

using ll = long long;

template <class T>
using grid = vector<vector<T>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n);
  vector<ll> y(n);
  REP(i, n) cin >> y[i];

  ll YMAX = 10000;
  vector<vector<ll>> table(n + 1);
  REP(i, n + 1) {
    if (i == n) table[i] = vector<ll>(YMAX + 1, 0);
    else table[i] = vector<ll>(YMAX + 1);
  }

  REPD(i, n) {
    ll minv = LLONG_MAX;
    FORD(h, YMAX, 0) {
      minv = min(minv, table[i + 1][h] + abs(y[i] - h));
      table[i][h] = minv;
    }
  }

  print(table[0][0]);
}
0