結果

問題 No.21 平均の差
ユーザー gemygemy
提出日時 2023-09-15 21:23:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,612 ms / 5,000 ms
コード長 1,621 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 251,436 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 21:23:28
合計ジャッジ時間 10,750 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) begin(v), end(v)
using namespace std;
using ll = long long int;

vector<vector<int>> MakeCombination(int n, int k) {
    vector<vector<int>> ret;
    vector<int> temp = {0};
    auto f = [&](auto f, int i, int m) -> void {
        if (m == k) {
            temp.push_back(n);
            ret.push_back(temp);
            temp.pop_back();
        } else {
            for (int j = i + 1; j <= n - k + m; j++) {
                temp.push_back(j);
                f(f, j, m + 1);
                temp.pop_back();
            }
        }
    };
    f(f, 0, 0);
    return ret;
}

int main() {
    // 入力
    int N, K;
    cin >> N >> K;
    vector<int> n(N);
    rep(i, N) cin >> n[i];

    // 分け方の全探索
    vector<vector<int>> pat = MakeCombination(N, K - 1);
    int MaxAveDiff = 0;
    vector<int> v(N);
    rep(i, N) v[i] = i;

    do {
        for (auto w : pat) {
            // 各組の平均点と平均の差の最大値
            vector<double> score(K, 0);
            double MaxAve = 0, MinAve = 10000;
            rep(i, K) {
                for (int j = w[i]; j < w[i + 1]; j++) score[i] += n[v[j]];
                score[i] /= (w[i + 1] - w[i]);
                MaxAve = max(MaxAve, score[i]);
                MinAve = min(MinAve, score[i]);
            }

            // 最大の平均の差の更新
            MaxAveDiff = max(MaxAveDiff, (int)(MaxAve - MinAve + 0.9999));
        }
    } while (next_permutation(all(v)));

    // 出力
    cout << MaxAveDiff << endl;
}
0