結果

問題 No.21 平均の差
ユーザー startcppstartcpp
提出日時 2015-11-01 15:11:00
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 972 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 53,568 KB
実行使用メモリ 7,468 KB
最終ジャッジ日時 2023-10-11 07:48:52
合計ジャッジ時間 7,300 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 7 ms
4,348 KB
testcase_02 AC 27 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//全部試して一番良いものを取る
#include <iostream>
using namespace std;

int pwd( int a, int n ){
	if( n == 0 )
		return 1;
	return a * pwd(a, n - 1);
}
int n;
int k;
int c[9];

int main()
{
	int i, j;
	cin >> n >> k;
	for( int i = 0; i < n; i++ )
		cin >> c[i];
	
	int ans = 0;
	//n桁のk進数で振り分け方を列挙
	for( i = 0; i < pwd(k, n); i++ ){
		int groupSz[9] = {0};
		int groupSum[9] = {0};
		for( j = 0; j < n; j++ ){
			int groupInd = (i / pwd(k, j)) % k;
			groupSz[groupInd]++;
			groupSum[groupInd] += c[j];
		}
		
		for( j = 0; j < k; j++ ){
			if( groupSz[j] == 0 )
				break;
		}
		if( j < k )
			continue;
			
		double mini = (double)groupSum[0] / groupSz[0];
		double maxi = (double)groupSum[0] / groupSz[0];
		for( j = 0; j < k; j++ ){
			mini = min( mini, (double)groupSum[j] / groupSz[j] );
			maxi = max( maxi, (double)groupSum[j] / groupSz[j] );
		}
		ans = max(ans, (int)(maxi - mini) );
	}
	cout << ans << endl;
	return 0;
}
0