結果

問題 No.837 Noelちゃんと星々2
ユーザー jelljell
提出日時 2019-06-15 16:01:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,273 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 169,220 KB
実行使用メモリ 5,000 KB
最終ジャッジ日時 2023-09-02 07:25:25
合計ジャッジ時間 3,482 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
4,920 KB
testcase_01 AC 48 ms
4,836 KB
testcase_02 AC 49 ms
4,984 KB
testcase_03 AC 49 ms
4,864 KB
testcase_04 AC 49 ms
4,832 KB
testcase_05 AC 48 ms
4,844 KB
testcase_06 AC 49 ms
4,992 KB
testcase_07 AC 48 ms
4,816 KB
testcase_08 AC 48 ms
5,000 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using i64=int_fast64_t;

int n;
i64 hei[1<<17];
i64 hsum[1<<17];
const i64 inf=1e18;

//for [l,r]
i64 calc(int l,int r) {
    return hei[r+1]-hei[l];
}

int main() {
    cin>>n;
    for(int i=0; i<n; ++i) cin>>hei[i];
    sort(hei,hei+n);
    if(hei[0]==hei[n-1]) {
        cout<<1<<endl;
        return 0;
    }

    for(int i=0; i<n; ++i) {
        hsum[i+1]=hsum[i]+hei[i];
    }

    i64 ans=inf;
    for(int i=1; i<n; ++i) {
        i64 ll=0,rr=0;
        pii lmid,rmid;

        //left part
        {
            int l=(i-1)/2;
            if(i&1) {
                lmid={hei[l],hei[l]};
                ll+=hsum[i]-hsum[l+1]-hsum[l];
            } else {
                lmid={hei[l],hei[l+1]};
                ll+=hsum[i]-hsum[l+1]*2;
            }
        }

        //right part
        {
            int r=(n-1+i)/2;
            if((n-i)&1) {
                rmid={hei[r],hei[r]};
                rr+=hsum[n]-hsum[r+1]-(hsum[r]-hsum[i]);
            } else {
                rmid={hei[r],hei[r+1]};
                rr+=hsum[n]-hsum[r+1]-(hsum[r+1]-hsum[i]);
            }
        }

        if(lmid.first!=rmid.second) {
            ans=min(ans,ll+rr);
        }
    }
    cout<<ans<<endl;
}
0