結果

問題 No.21 平均の差
ユーザー DrafearDrafear
提出日時 2016-01-18 03:08:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 869 bytes
コンパイル時間 1,239 ms
コンパイル使用メモリ 163,648 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 00:32:50
合計ジャッジ時間 2,009 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define int long long

int ans = 0, need = 0;
vector<int> cnt, sum;
vector<int> v;
int N, K;
void dfs(int n) {
	if (need > N-n) return;
	if (n == N) {
		int m = 0, M = 0;
		for (int i = 0; i < K; ++i) {
			assert(cnt[i] > 0);
			if (sum[i]*cnt[m] < sum[m]*cnt[i]) {
				m = i;
			}
			if (sum[i]*cnt[M] > sum[M]*cnt[i]) {
				M = i;
			}
		}
		int num = sum[M]*cnt[m]-sum[m]*cnt[M];
		int den = cnt[M]*cnt[m];
		ans = max(ans, (num+den-1)/den);
	}
	else {
		for (int i = 0; i < K; ++i) {
			if (cnt[i] == 0) --need;
			cnt[i]++;
			sum[i] += v[n];
			dfs(n+1);
			sum[i] -= v[n];
			--cnt[i];
			if (cnt[i] == 0) ++need;
		}
	}
}
signed main() {
	cin >> N >> K;
	v.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
	}
	cnt = vector<int>(K, 0);
	sum = vector<int>(K, 0);
	need = K;
	dfs(0);
	cout << ans << endl;
}
0