結果

問題 No.247 線形計画問題もどき
ユーザー TawaraTawara
提出日時 2015-07-18 23:39:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 931 ms
コンパイル使用メモリ 77,728 KB
実行使用メモリ 43,028 KB
最終ジャッジ日時 2023-09-21 17:32:00
合計ジャッジ時間 2,298 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
17,308 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 65 ms
43,028 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 4 ms
5,532 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 11 ms
12,460 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 30 ms
29,904 KB
testcase_20 AC 37 ms
35,708 KB
testcase_21 AC 5 ms
6,468 KB
testcase_22 AC 9 ms
10,552 KB
testcase_23 AC 6 ms
7,200 KB
testcase_24 AC 38 ms
36,240 KB
testcase_25 AC 27 ms
27,308 KB
testcase_26 AC 7 ms
7,980 KB
testcase_27 AC 10 ms
11,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef vector <string> VS;
typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, LL> PIL;
typedef vector <PIL> VPIL;

#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define sort(c) sort((c).begin(),(c).end())

#define range(i,a,b) for(int i=(a); i < (b); i++)
#define rep(i,n) range(i,0,n)

#define MAX_INT 2147483647

int main(){
	int C, N, UB = 100001;
	VI a;
	VVI dp;
	cin >> C >> N;
	a.resize(N);
	rep(i,N) cin >> a[i];
	dp = VVI(N+1, VI(C+1, UB));
	rep(i,N){
		dp[i][0] = 0;
		range(j,a[i],C+1) dp[i][j] = min(dp[i][j], dp[i][j-a[i]]+1);
		rep(j,C+1) dp[i+1][j] = dp[i][j]; 
	}
  	cout << ((dp[N][C] != UB)? dp[N][C] : -1) << endl;
	return 0;
}
0