結果
問題 | No.838 Noelちゃんと星々3 |
ユーザー |
![]() |
提出日時 | 2020-06-16 23:34:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 961 bytes |
コンパイル時間 | 2,727 ms |
コンパイル使用メモリ | 196,948 KB |
最終ジャッジ日時 | 2025-01-11 04:47:19 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#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; }