結果

問題 No.838 Noelちゃんと星々3
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-16 23:34:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 203,312 KB
実行使用メモリ 4,684 KB
最終ジャッジ日時 2023-09-16 11:13:17
合計ジャッジ時間 3,250 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
4,684 KB
testcase_01 AC 24 ms
4,624 KB
testcase_02 AC 23 ms
4,676 KB
testcase_03 AC 23 ms
4,680 KB
testcase_04 AC 23 ms
4,620 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,500 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

ll dp[101000];

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> y(n);
  rep(i, n) cin >> y[i];
  sort(y.begin(), y.end());
  rep(i, 101000) dp[i] = LINF;
  dp[0] = 0;
  rep(i, n) {
    if(i+1 < n) chmin(dp[i+2], dp[i]+y[i+1]-y[i]);
    if(i+2 < n) chmin(dp[i+3], dp[i]+y[i+2]-y[i]);
  }
  cout << dp[n] << '\n';
  return 0;
}
0