結果

問題 No.385 カップ麺生活
ユーザー highdhighd
提出日時 2016-09-07 19:31:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 73,388 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:35:43
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
void primes(std::vector<int>&prime_list, int n) {
	if(n<2)return;
	prime_list.resize(n - 2);
	for (int i = 2; i<n; i++) {
		prime_list.at(i - 2) = i;
	}
	int front_index=0;
	while (1) {
		int front = prime_list.at(front_index);
		auto it = prime_list.begin();
		while (it != prime_list.end()) {
			if (*it%front == 0 && *it != front) {
				it = prime_list.erase(it);
			} else {
				++it;
			}
		}
		if (front*front>n)break;
		++front_index;
	}
}

void run(int*node_list, int length, std::vector<int>&cs,int value,int count) {
	for (auto c : cs) {
		if (c + value < length&&node_list[c + value]<count) {
			node_list[c+value]=count;
			run(node_list,length,cs,c+value,count+1);
		}
	}
}
int buy(int*node_list, std::vector<int>&prime_list,int maney,std::vector<int>&cs) {
	int sum=0;
	for (auto v : prime_list) {
		if (node_list[maney-v] > 0) {
			sum+=node_list[maney - v];
		}
	}
	sum+=maney/ cs[0];
	return sum;
}
int main() {
	int n, m;
	std::cin >> m >> n;
	std::vector<int> cs(n);
	for (int i = 0; i<n; i++) {
		std::cin >> cs.at(i);
	}
	std::sort(cs.begin(),cs.end());
	std::vector<int> prime_list;
	int*node_list=new int[m];
	for (int i = 0; i < m;i++) {
		node_list[i]=-1;
	}
	node_list[0]=0;
	run(node_list,m,cs,0,1);
	primes(prime_list, m);
	std::cout<<buy(node_list,prime_list,m,cs)<<std::endl;
	delete[] node_list;
}
0