結果

問題 No.198 キャンディー・ボックス2
ユーザー Kmcode1Kmcode1
提出日時 2015-04-29 02:26:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,495 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 100,036 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-19 04:00:08
合計ジャッジ時間 29,163 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 954 ms
4,380 KB
testcase_01 AC 955 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 955 ms
4,380 KB
testcase_10 RE -
testcase_11 AC 958 ms
4,380 KB
testcase_12 AC 955 ms
4,384 KB
testcase_13 WA -
testcase_14 RE -
testcase_15 AC 956 ms
4,380 KB
testcase_16 RE -
testcase_17 AC 956 ms
4,376 KB
testcase_18 AC 954 ms
4,380 KB
testcase_19 AC 955 ms
4,380 KB
testcase_20 AC 955 ms
4,376 KB
testcase_21 AC 955 ms
4,380 KB
testcase_22 AC 955 ms
4,384 KB
testcase_23 AC 955 ms
4,376 KB
testcase_24 AC 955 ms
4,380 KB
testcase_25 AC 956 ms
4,380 KB
testcase_26 AC 955 ms
4,380 KB
testcase_27 AC 955 ms
4,384 KB
testcase_28 AC 955 ms
4,380 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;
//MT random generator
using namespace std;

typedef unsigned int uint;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define FI(n) FastIO::read_int(n)
#define FO(n) FastIO::write_int(n)

#define CLK CLOCKS_PER_SEC
#define pb push_back
#define X first
#define Y second
#define MT_N 624
#define MT_M 397
#define MT_MSB 0x80000000U
#define MT_LS31B 0x7FFFFFFFU
#define MT_A 2567483615U
class MersenneTwister {		/* pseudo-random number generator */
	uint twistory[MT_N];	// history (i.e., previous states) of the generator
	int pos;
public:
	MersenneTwister(uint seed = 0) {
		twistory[0] = seed;
		for (int i = 1; i < MT_N; i++) twistory[i] = 1812433253U * (twistory[i - 1] ^ (twistory[i - 1] >> 30)) + i;
		pos = 0;
	}
	void reset(uint seed = 0) {
		twistory[0] = seed;
		for (int i = 1; i < MT_N; i++) twistory[i] = 1812433253U * (twistory[i - 1] ^ (twistory[i - 1] >> 30)) + i;
		pos = 0;
	}
	void generate(void) {
		uint tmp;
		int i;
		for (i = 0; i < MT_N - MT_M; i++) {
			tmp = (twistory[i] & MT_MSB) + (twistory[i + 1] & MT_LS31B);
			twistory[i] = twistory[i + MT_M] ^ (tmp >> 1) ^ (MT_A & -(tmp & 1));
		}
		for (; i < MT_N - 1; i++) {
			tmp = (twistory[i] & MT_MSB) + (twistory[i + 1] & MT_LS31B);
			twistory[i] = twistory[i + MT_M - MT_N] ^ (tmp >> 1) ^ (MT_A & -(tmp & 1));
		}
		tmp = (twistory[i] & MT_MSB) + (twistory[0] & MT_LS31B);
		twistory[i] = twistory[MT_M - 1] ^ (tmp >> 1) ^ (MT_A & -(tmp & 1));
	}
	uint rand_unsigned() {
		if (!pos) generate();
		uint ans = twistory[pos++];
		pos &= -(pos != 624);
		ans ^= ans >> 11;
		ans ^= (ans << 7) & 2636928640U;
		ans ^= (ans << 15) & 4022730752U;
		ans ^= ans >> 18;
		return ans;
	}
	double next_double() { return 1.0 * rand_unsigned() / MT_LS31B; }
	int rand_signed() { return rand_unsigned() >> 1; }
	int next_int(int n) { if (n == 1) return 0; return rand_unsigned() % n; }
	int next_int(int a, int b) { if (a == b) return a; return rand_unsigned() % (b - a + 1) + a; }
} rnd(1028);

inline int next_int(int a, int b) { return rnd.next_int(a, b); }
inline int next_int(int n) { return rnd.next_int(n); }
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(next_int(maxt)));
	}
	printf("%lld\n", mint);
	return 0;
}
0