結果
問題 |
No.837 Noelちゃんと星々2
|
ユーザー |
|
提出日時 | 2019-06-15 15:25:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,238 bytes |
コンパイル時間 | 1,436 ms |
コンパイル使用メモリ | 169,616 KB |
実行使用メモリ | 5,504 KB |
最終ジャッジ日時 | 2024-06-11 14:22:20 |
合計ジャッジ時間 | 2,619 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include "bits/stdc++.h" // Custom Header <<< #define ALL(x) x.begin(), x.end() #define rep(i, s, n) for(int i(s); i < int(n); ++i) #define endl '\n' #ifndef YDK #define eprintf(...) #endif using namespace std; using i64 = long long; using pii = pair<int, int>; template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;} template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;} constexpr int INF = 0x3f3f3f3f; constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int MOD = int(1e9) + 7; // >>> struct FastIO { FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); } } fastIO_ydk ; signed main() { int N; int a[100010]; cin >> N; rep(i, 0, N) cin >> a[i]; sort(a, a+N); if (a[0] == a[N-1]) { cout << (1) << endl; return 0; } i64 x[100010] {}; i64 y[100010] {}; for (int i = 1; i < N; ++i) x[i] = x[i-1] + a[i] - a[i/2]; reverse(a, a+N); for (int i = 1; i < N; ++i) y[i] = y[i-1] - a[i] + a[i/2]; reverse(y, y+N); i64 ans = LINF; for (int i = 0; i+1 < N; ++i) { chmin(ans, x[i] + y[i+1]); } cout << (ans) << endl; return 0; } /* vim:set foldmethod=marker foldmarker=<<<,>>> : */