結果

問題 No.247 線形計画問題もどき
ユーザー kurenaifkurenaif
提出日時 2016-04-19 18:31:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,430 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 86,024 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 17:37:21
合計ジャッジ時間 1,644 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define pii pair<long long,long long>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define pi 2*acos(0.0)
#define INFILE() freopen("in.txt","r",stdin)
#define OUTFILE() freopen("out.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14

// l = list(map(int, input().split()))
// l = ts = [input() for i in range(n)]

//int dx[] = { 1,0,-1,0 };
//int dy[] = { 0,1,0,-1 };

int main(void) {
	int C; cin >> C;
	int N; cin >> N;
	vector<int> a(N); for (auto &aa : a) cin >> aa;
	vector<ull> dp(C + 1, inf);

	dp[0] = 0;

	FOR(i, 1, C+1) REP(j, N) if(i-a[j] >= 0)
			dp[i] = min(dp[i], dp[i - a[j]] + 1);

	if (dp[C] >= inf) cout << -1 << endl;
	else cout << dp[C] << endl;
	return 0;
}
0