結果

問題 No.385 カップ麺生活
ユーザー highd
提出日時 2016-09-06 20:16:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,717 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-15 20:58:09
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 9 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
void primes(std::vector<int>&prime_list, int n) {
	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;
	}
}
struct Node {
	int count_;
	Node*next_;
};
void run(Node*node_list, int length, std::vector<int>&cs,int value) {
	int now=node_list[value].count_;
	for (auto v : cs) {
		if (length > v + value&&node_list[v+value].count_<now) {
			node_list[value].next_=node_list+v+value;
			Node*now_node=node_list+v+value;
			int index=now+1;
			while (now_node!=nullptr) {
				now_node->count_=index;
				index++;
				now_node=now_node->next_;
			}
			run(node_list,length,cs,value+v);
		}
	}
}
int buy(Node*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].count_ > 0) {
			sum+=node_list[maney - v].count_;
		}
	}
	sum+=maney/ cs[0];
	return sum;
}
//100
//6
//10 2 4 7 8 1
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;
	Node*node_list=new Node[m];
	for (int i = 0; i < m;i++) {
		node_list[i].count_=-1;
		node_list[i].next_ = nullptr;
	}
	node_list[0].count_=0;
	run(node_list,m,cs,0);
	primes(prime_list, m);
	std::cout<<buy(node_list,prime_list,m,cs)<<std::endl;
	delete[] node_list;
}
0