結果

問題 No.837 Noelちゃんと星々2
ユーザー TangentDayTangentDay
提出日時 2019-06-14 21:44:32
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,483 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 90,032 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-11 14:13:21
合計ジャッジ時間 1,931 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int in()’:
main.cpp:36:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 | int in() { int x; scanf("%d", &x); return x; }
      |                   ~~~~~^~~~~~~~~~
main.cpp: In function ‘ll lin()’:
main.cpp:37:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 | ll lin() { ll x; scanf("%lld", &x); return x; }
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));

    if (a[0] == a[n - 1]){
        cout << 1 << endl;
        return 0;
    }

    VL s(n + 1);
    REP(i,n) s[i + 1] = s[i] + a[i];

    ll ans = 1e18;
    FOR(x,1,n-1){
        int i = x / 2;
        int j = (n - x) / 2 + x;
        ll tmp = a[i] * i - (s[i] - s[0])
               + (s[x] - s[i]) - a[i] * (x - i)
               + a[j] * (j - x) - (s[j] - s[x])
               + (s[n] - s[j]) - a[j] * (n - j);
        chmin(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}
0