結果

問題 No.1077 Noelちゃんと星々4
ユーザー hipotafhipotaf
提出日時 2020-06-12 22:54:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,214 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 75,728 KB
実行使用メモリ 11,484 KB
最終ジャッジ日時 2023-09-06 11:04:13
合計ジャッジ時間 6,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,384 KB
testcase_01 AC 5 ms
4,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 1000;
  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) {
    FORD(h, YMAX, 0) {
      ll cost = LLONG_MAX;
      FOR(j, h, YMAX) {
        cost = min(cost, table[i + 1][j] + abs(y[i] - j));
      }
      table[i][h] = cost;
    }
  }

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