結果

問題 No.617 Nafmo、買い出しに行く
ユーザー noshi91noshi91
提出日時 2017-12-18 18:47:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,669 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 88,472 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-22 05:45:06
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n, k, temp, ans;
	std::cin >> n >> k;
	std::vector<uint32> a(n);
	rep(i, 0, n)
		std::cin >> a[i];
	if (n <= 10) {
		std::vector<uint32> b(1 << n);
		auto itr = b.begin();
		*itr = 0;
		ans = k;
		rep(i, 0, n) {
			temp = 1 << i;
			rep(j, 0, temp) {
				++itr;
				*itr = b[j] + a[i];
				ans = std::min(ans, k - *itr);
			}
		}
		ans = k - ans;
	}
	else {
		std::vector<uint32> b(1 << 10), c(1 << (n - 10));
		auto itr = b.begin();
		*itr = 0;
		rep(i, 0, 10) {
			temp = 1 << i;
			rep(j, 0, temp) {
				++itr;
				*itr = b[j] + a[i];
			}
		}
		itr = c.begin();
		*itr = 0;
		rep(i, 10, n) {
			temp = 1 << (i - 10);
			rep(j, 0, temp) {
				++itr;
				*itr = c[j] + a[i];
			}
		}
		std::sort(c.begin(), c.end(), std::greater<uint32>());
		ans = 0;
		rep(i, 0, 1 << 10) {
			if (b[i] <= k) {
				ans = std::max(ans, b[i] + *std::lower_bound(c.begin(), c.end(), k - b[i], std::greater<uint32>()));
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}
0