結果

問題 No.198 キャンディー・ボックス2
ユーザー kyuridenamidakyuridenamida
提出日時 2015-04-28 23:52:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 149,272 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 14:18:20
合計ジャッジ時間 2,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;




long long f(vector<long long> A,long long x){
	long long cnt = 0;
	for(int i = 0 ; i < A.size() ; i++) cnt +=  abs(A[i]-x);
	return cnt;
}
int main(){
	long long B,N;
	cin >> B >> N;
	vector<long long> C(N);
	long long sum = B;
	for(int i = 0 ; i < N ; i++){
		cin >> C[i];
		sum += C[i];
	}
	sum /= N;
	vector<long long> cand;
	for(int i = 1 ; i < (1<<N) ; i++){
		long long s = 0;
		for(int j = 0 ; j < N ; j++){
			if( i >> j & 1 ) s += C[j];
		}
		s /= __builtin_popcount(i);
		for(int k = -10 ; k <= 10 ; k++){
			long long t = s + k;
			if( t >= 0 ) cand.push_back(t);
		}
	}
	long long ans = 1e15;
	for( auto x : cand ){
		ans = min(f(C,x),ans);
		//cout << x << ": " << f(C,x) << endl;
	}

	cout << ans << endl;
	
	
}
0