結果

問題 No.837 Noelちゃんと星々2
ユーザー rookzenorookzeno
提出日時 2019-06-15 01:09:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,400 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 177,236 KB
実行使用メモリ 61,656 KB
最終ジャッジ日時 2023-09-02 07:23:16
合計ジャッジ時間 4,191 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
61,656 KB
testcase_01 AC 76 ms
61,576 KB
testcase_02 AC 76 ms
61,456 KB
testcase_03 AC 75 ms
61,460 KB
testcase_04 AC 78 ms
61,404 KB
testcase_05 AC 77 ms
61,400 KB
testcase_06 AC 77 ms
61,444 KB
testcase_07 AC 77 ms
61,464 KB
testcase_08 AC 77 ms
61,456 KB
testcase_09 AC 19 ms
56,220 KB
testcase_10 AC 19 ms
56,192 KB
testcase_11 AC 19 ms
55,944 KB
testcase_12 AC 19 ms
55,936 KB
testcase_13 AC 20 ms
55,936 KB
testcase_14 AC 19 ms
56,264 KB
testcase_15 AC 19 ms
56,052 KB
testcase_16 AC 19 ms
56,052 KB
testcase_17 AC 19 ms
55,952 KB
testcase_18 AC 18 ms
56,004 KB
testcase_19 AC 19 ms
55,944 KB
testcase_20 AC 19 ms
56,052 KB
testcase_21 AC 19 ms
56,004 KB
testcase_22 AC 19 ms
55,984 KB
testcase_23 AC 19 ms
56,060 KB
testcase_24 AC 19 ms
55,944 KB
testcase_25 AC 19 ms
55,948 KB
testcase_26 AC 20 ms
55,996 KB
testcase_27 AC 19 ms
55,944 KB
testcase_28 AC 19 ms
56,056 KB
testcase_29 AC 19 ms
55,940 KB
testcase_30 AC 19 ms
56,000 KB
testcase_31 AC 19 ms
56,000 KB
testcase_32 AC 18 ms
56,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';


}
0