結果

問題 No.838 Noelちゃんと星々3
ユーザー cotton_fn_cotton_fn_
提出日時 2019-06-14 22:32:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 117,172 KB
実行使用メモリ 6,172 KB
最終ジャッジ日時 2023-08-09 01:48:41
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
6,172 KB
testcase_01 AC 49 ms
5,980 KB
testcase_02 AC 49 ms
5,992 KB
testcase_03 AC 48 ms
5,976 KB
testcase_04 AC 49 ms
6,052 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> y, dp[3];
int main() {
  cin >> n;
  read_n(y, n);
  sort(begin(y), end(y));
  y.insert(begin(y), 0);

  for (i64 i = 0; i < 3; ++i) init_n(dp[i], n + 1);
  dp[1][1] = dp[2][1] = 1ll << 50;
  for (i64 i = 1; i <= n; ++i) {
    if (i < n) {
      dp[0][i] = min(dp[1][i - 1], dp[2][i - 1]) + y[i + 1] - y[i]; // to succ
    }
    if (i > 1) {
      dp[1][i] = dp[0][i - 1]; // stay
      dp[2][i] = dp[1][i - 1] + y[i] - y[i - 1]; // to prev
    }
  }

  cout << min(dp[1][n], dp[2][n]) << '\n';
  return 0;
}

0