結果
問題 | No.837 Noelちゃんと星々2 |
ユーザー | Arumakan1727 |
提出日時 | 2019-06-15 12:48:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 1,864 bytes |
コンパイル時間 | 1,617 ms |
コンパイル使用メモリ | 173,016 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-11 14:22:17 |
合計ジャッジ時間 | 3,080 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; // >>> using v64 = vector<long long>; template<class Array> v64 ruisekiwa(const Array src, int N) { v64 s(N, src[0]); for (int i = 1; i < N; ++i) s[i] = s[i-1] + src[i]; return s; } // [l, r] inline long long partSum(const v64 &s, int l, int r) { if (l > r) swap(l, r); return s[r] - (l <= 0 ? 0 : s[l-1]); } 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; } v64 s = ruisekiwa(a, N); // [l, r) const auto medianDiffSum = [&](int l, int r) -> i64 { const int N = r - l; const int mid = (l + r) / 2; if (N == 1) { return 0; } if (N % 2 == 0) { return partSum(s, mid, r-1) - partSum(s, l, mid-1); } else { return partSum(s, mid+1, r-1) - partSum(s, l, mid-1); } }; v64 ans; ans.reserve(N); for (int d = 1; d < N; ++d) { const auto x = medianDiffSum(0, d); const auto y = medianDiffSum(d, N); eprintf("[0, %d) = %2lld, [%d, N) = %2lld\n", d, x, d, y); ans.push_back(x + y); } cout << (*min_element(ALL(ans))) << endl; return 0; } /* vim:set foldmethod=marker foldmarker=<<<,>>> : */