結果

問題 No.247 線形計画問題もどき
ユーザー yudedakoyudedako
提出日時 2015-11-05 13:15:25
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,147 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 60,204 KB
実行使用メモリ 7,764 KB
最終ジャッジ日時 2023-10-11 13:56:02
合計ジャッジ時間 4,096 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <iostream>
#include <climits>
void sort(std::vector<int> &vector, int left, int right) {
	if (left < right) {
		auto l = left, r = right, pivot = vector.at((left + right) / 2);
		while (l < r) {
			while (vector.at(l) > pivot)++l;
			while (vector.at(r) < pivot)--r;
			if (l < r) {
				auto temp = vector.at(l);
				vector.at(l) = vector.at(r); vector.at(r) = temp;
				++l; --r;
			}
			sort(vector, left, r), sort(vector, r + 1, right);
		}
	}
}
int main() {
	int c, n;
	std::cin >> c >> n;
	std::vector<int> vector(c + 1, INT_MAX);
	std::vector<int> arr(n, 0);
	for (auto &i : arr) {
		int a;
		std::cin >> a;
		i = a;
	}
	sort(arr, 0, arr.size() - 1);
	vector.at(0) = 0;
	int min = INT_MAX;
	for (const auto &a : arr) {
		for (auto i = 0; i < c + 1; ++i) {
			if (vector.at(i) < min && (i + a <= c) && (vector.at(i + a) > vector.at(i) + 1)) {
				vector.at(i + a) = vector.at(i) + 1;
				if ((i + a == c) && (min > vector.at(i + a))) {
					min = vector.at(i + a);
				}
			}
		}
	}
	if (vector.at(c) == INT_MAX) {
		std::cout << -1 << std::endl;
	}
	else {
		std::cout << vector.at(c) << std::endl;
	}
	return 0;
}
0