結果

問題 No.198 キャンディー・ボックス2
ユーザー Kmcode1
提出日時 2015-04-29 01:42:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,346 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 100,048 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 16:31:12
合計ジャッジ時間 31,196 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |         scanf("%lld", &b);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:48:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:53:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |                 scanf("%lld", &a);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

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