結果

問題 No.837 Noelちゃんと星々2
ユーザー ahe100ahe100
提出日時 2019-06-15 00:20:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,025 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 167,620 KB
実行使用メモリ 6,812 KB
最終ジャッジ日時 2023-08-09 20:00:33
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
6,548 KB
testcase_01 AC 48 ms
6,508 KB
testcase_02 AC 49 ms
6,672 KB
testcase_03 AC 48 ms
6,440 KB
testcase_04 AC 51 ms
6,532 KB
testcase_05 AC 50 ms
6,448 KB
testcase_06 AC 49 ms
6,676 KB
testcase_07 AC 51 ms
6,812 KB
testcase_08 AC 50 ms
6,528 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 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,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 WA -
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,a[100010],b[100010],ru[100010],ru2[100010],ans=1e18;

void init(){
	cin>>n;
	reg(i,1,n)cin>>a[i];
	sort(a+1,a+n+1);
	ru[0]=0;
	reg(i,1,n)ru[i]=ru[i-1]+a[i];
	ireg(i,1,n)b[i]=b[n]-a[i];
	ru2[n+1]=0;
	ireg(i,1,n)ru2[i]=ru2[i+1]+b[i];
}

int main(void){
	init();
	reg(i,1,n-1){  // 1~iまでを同じ数字にする
		ll sum1=0,sum2=0,sum3=0,sum4=0;
		sum1 += ru2[1]-ru2[(i+1)/2+1]-((i+1)/2-1+1)*b[(i+1)/2];
		sum2 += ru[i]-ru[(i+1)/2-1]-(i-(i+1)/2+1)*a[(i+1)/2];
		sum3 += ru2[i+1]-ru2[(n+i+1)/2+1]-((n+i+1)/2-(i+1)+1)*b[(n+i+1)/2];
		sum4 += ru[n]-ru[(n+i+1)/2-1]-(n-(n+i+1)/2+1)*a[(n+i+1)/2];
		// cout<<sum1<<" "<<sum2<<" "<<sum3<<" "<<sum4<<endl;
		ans=min(ans, sum1+sum2+sum3+sum4);
	}
	cout<<ans<<endl;
	return 0;
}
0