結果

問題 No.385 カップ麺生活
ユーザー kotamanegikotamanegi
提出日時 2016-07-01 22:39:38
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,306 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 91,244 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-04 22:23:10
合計ジャッジ時間 1,653 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
vector<int> hoge;
bool not_sosuu[1000000] = {};
int dp[1000000] = {};
void settings() {
	not_sosuu[0] = true;
	not_sosuu[1] = true;
	for (int i = 2;i < 100000;++i) {
		for (int q = 2;q*i < 100000;++q) {
			not_sosuu[i*q] = true;
		}
	}
}
int main() {
	long long m, n;
	cin >> m >> n;
	settings();
	for (int i = 0;i < n;++i) {
		int a;
		cin >> a;
		hoge.push_back(a);
	}
	sort(hoge.begin(), hoge.end());
	dp[m] = 1;
	for (int i = m;i > 0;--i) {
		for (int q = 0;q < hoge.size();++q) {
			if (i >= hoge[q]&&dp[i] != 0) {
				dp[i - hoge[q]] = max(dp[i-hoge[q]],dp[i] + 1);
			}
		}
	}
	long long ans = 0;
	int  final_push = 0;
	for (int i = 0;i <= m;++i) {
		final_push = max(final_push, dp[i]-1);
		if (not_sosuu[i] == false&&dp[i] != 0) {
			ans += dp[i]-1;
		}
	}
	cout << final_push + ans << endl;
}
0