結果

問題 No.2370 He ate many cakes
ユーザー 👑 hitonanodehitonanode
提出日時 2023-07-14 10:01:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 109,968 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-13 23:06:08
合計ジャッジ時間 2,337 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 17 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 11 ms
4,352 KB
testcase_11 AC 17 ms
4,356 KB
testcase_12 AC 12 ms
4,348 KB
testcase_13 AC 18 ms
4,352 KB
testcase_14 AC 19 ms
4,352 KB
testcase_15 AC 18 ms
4,352 KB
testcase_16 AC 12 ms
4,352 KB
testcase_17 AC 18 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using lint = long long;

vector<lint> gen(const vector<int> &vec) {
    vector<lint> ret;
    ret.reserve(1 << vec.size());
    auto rec = [&](auto &&self, int now, lint sum) -> void {
        if (now == (int)vec.size()) {
            ret.push_back(sum);
            return;
        }
        self(self, now + 1, sum);
        self(self, now + 1, sum + vec.at(now));
    };
    rec(rec, 0, 0);
    return ret;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (auto &x : A) cin >> x;

    const int L = N / 2;
    auto left = gen(vector<int>(A.begin(), A.begin() + L));
    sort(left.rbegin(), left.rend());
    auto right = gen(vector<int>(A.begin() + L, A.end()));
    sort(right.begin(), right.end());

    lint ok = -1e9 * 30, ng = 1e9 * 30 + 10;
    while (ng > ok + 1) {
        const lint c = (ok + ng) / 2;
        int cntr = 0;
        for (lint v : left) {
            cntr += right.cend() - lower_bound(right.cbegin(), right.cend(), c - v);
            if (cntr >= K) break;
        }
        (cntr >= K ? ok : ng) = c;
    }
    cout << ok << '\n';
}
0