結果

問題 No.385 カップ麺生活
ユーザー kotamanegikotamanegi
提出日時 2016-07-01 22:39:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,306 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 89,620 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:26:23
合計ジャッジ時間 1,863 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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