結果
| 問題 |
No.837 Noelちゃんと星々2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-15 01:09:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 2,400 bytes |
| コンパイル時間 | 1,712 ms |
| コンパイル使用メモリ | 179,036 KB |
| 実行使用メモリ | 59,008 KB |
| 最終ジャッジ日時 | 2024-06-11 14:19:10 |
| 合計ジャッジ時間 | 4,410 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head
int m,n,k,res,tmp,tmp2,tmp3,h,w,x,y;
VI a;
deque<PII> que;
string s;
//VI b;
vector<PII> g[2100600];
int b[2100000];
int c[210000] = {};
int rui[210000];
set<int> ch;
#define N 100008
class BIT {
int n;
ll data[N];
public:
BIT(int n) : n(n) {
for(int i = 0; i < n+2; ++i) data[i] = 0;
}
void add(int k, ll x) {
while(k <= n) {
data[k] += x;
k += k & -k;
}
}
ll get(int k) {
ll s = 0;
while(k) {
s += data[k];
k -= k & -k;
}
return s;
}
};
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin>>n;
rep(i,0,n){
cin>>b[i];
// b[i] += 1LL<<30;
ch.insert(b[i]);
}
sort(b,b+n);
if(ch.size()==1){cout << 1 << '\n'; exit(0);}
BIT bit(n+1);
rep(i,0,n){
bit.add(i+1,b[i]);
}
int ans = INF;
rep(i,0,n){
x = i/2;
tmp = bit.get(i/2+1);
tmp2 = bit.get(i+1);
int mae = b[x]*(x+1)-tmp+(tmp2-tmp)-b[x]*(i-x);
y = (n+i)/2;
tmp3 = bit.get(y+1);
int tmp4 = bit.get(n);
int usi = b[y]*(y-i)-(tmp3-tmp2) +(tmp4-tmp3)-b[y]*(n-y-1);
// cout << mae <<" "<<usi<< '\n';
ans = min(ans,mae+usi);
}
cout << ans << '\n';
}