結果

問題 No.198 キャンディー・ボックス2
ユーザー Kmcode1Kmcode1
提出日時 2015-04-29 02:11:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,391 bytes
コンパイル時間 755 ms
コンパイル使用メモリ 100,124 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-19 03:59:07
合計ジャッジ時間 29,311 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 = LLONG_MAX;
	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 = min(mint,countt(mint));
	}
	mint = min(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)));
	}
	printf("%lld\n", mint);
	return 0;
}
0