結果

問題 No.198 キャンディー・ボックス2
ユーザー Kmcode1Kmcode1
提出日時 2015-04-29 01:42:37
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,346 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 100,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-19 03:55:53
合計ジャッジ時間 31,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<valarray>
//#include<bits/stdc++.h>
using namespace std;

long long int b;
int n;
unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
vector<long long int> v;
long long int countt(long long int a){
	long long int r = 0;
	for (int i = 0; i < v.size(); i++){
		r += abs(v[i] - a);
	}
	return r;
}
int main(){
	scanf("%lld", &b);
	scanf("%d", &n);
	long long int mint = 0;
	long long int maxt = 0;
	for (int i = 0; i < n; i++){
		long long int a;
		scanf("%lld", &a);
		v.push_back(a);
		maxt += a;
	}
	mint = countt(maxt / n);
	maxt += b;
	maxt /= (long long int)(n);
	mint = min(mint, countt(maxt));
	while (clock() / (double)(CLOCKS_PER_SEC) < 0.95){
		mint = min(mint, countt(randxor() % (maxt + 1LL)));
	}
	printf("%lld\n", mint);
	return 0;
}
0