結果

問題 No.2370 He ate many cakes
ユーザー ゆにぽけゆにぽけ
提出日時 2023-10-17 19:18:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 133,420 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 19:18:33
合計ジャッジ時間 3,448 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
using namespace std;
int N,K,A[30];
void solve()
{
	cin >> N >> K;
	for(int i = 0;i < N;i++) cin >> A[i];
	vector<long long> D,U;
	for(int i = 0;i < 1 << N/2;i++) 
	{
		long long s = 0;
		for(int j = 0;j < N/2;j++) if(i >> j & 1) s += A[j];
		D.push_back(s);
	}
	for(int i = 0;i < 1 << N-N/2;i++)
	{
		long long s = 0;
		for(int j = 0;j < N-N/2;j++) if(i >> j & 1) s += A[j+N/2];
		U.push_back(s);
	}
	sort(D.begin(),D.end(),greater<long long>());
	sort(U.begin(),U.end());
	long long ok = -2e18,ng = 2e18;
	while(ng-ok > 1)
	{
		long long mid = (ok+ng)/2;
		long long cnt = 0;
		int id = 0;
		for(int i = 0;i < (int)D.size();i++)
		{
			while(id < (int)U.size() && D[i]+U[id] < mid) id++;
			cnt += (int)U.size()-id;
		}

		if(cnt >= K) ok = mid;
		else ng = mid;
	}

	cout << ok << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
}
0