結果

問題 No.609 Noelちゃんと星々
ユーザー kzyKTkzyKT
提出日時 2017-12-09 00:24:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 170,172 KB
実行使用メモリ 12,380 KB
最終ジャッジ日時 2024-05-07 06:19:18
合計ジャッジ時間 3,956 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
10,556 KB
testcase_01 AC 23 ms
7,016 KB
testcase_02 AC 14 ms
5,652 KB
testcase_03 AC 21 ms
6,820 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 72 ms
11,960 KB
testcase_06 AC 57 ms
10,904 KB
testcase_07 AC 31 ms
7,696 KB
testcase_08 AC 7 ms
5,376 KB
testcase_09 AC 17 ms
5,816 KB
testcase_10 AC 39 ms
8,516 KB
testcase_11 AC 36 ms
8,224 KB
testcase_12 AC 49 ms
10,268 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 61 ms
11,128 KB
testcase_16 AC 77 ms
12,176 KB
testcase_17 AC 53 ms
10,564 KB
testcase_18 AC 15 ms
5,632 KB
testcase_19 AC 62 ms
10,916 KB
testcase_20 AC 79 ms
12,380 KB
testcase_21 AC 77 ms
12,360 KB
testcase_22 AC 79 ms
12,380 KB
testcase_23 AC 77 ms
12,376 KB
testcase_24 AC 82 ms
12,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  map<ll,ll> m;
  rep(i,n) m[a[i]]++;
  vector<P> v;
  tr(it,m) v.pb(P(it->F,it->S));
  ll sum=0;
  REP(i,1,v.size()) sum+=(v[i].F-v[0].F)*v[i].S;
  ll ans=sum,x=0,y=n;
  REP(i,1,v.size()) {
    x+=v[i-1].S;
    y-=v[i-1].S;
    sum+=(v[i].F-v[i-1].F)*x;
    sum-=(v[i].F-v[i-1].F)*y;
    ans=min(ans,sum);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0