結果

問題 No.247 線形計画問題もどき
ユーザー 沙耶花沙耶花
提出日時 2022-03-17 20:21:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 4,289 ms
コンパイル使用メモリ 255,576 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 19:13:38
合計ジャッジ時間 4,723 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000000000001


int main(){
	int n,c;
	cin>>c>>n;
	
	vector<long long> dp(c+1,Inf);
	dp[0] = 0;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	
	rep(i,n){
		rep(j,c+1){
			if(j-a[i]<0)continue;
			dp[j] = min(dp[j], dp[j-a[i]]+1);
		}
	}
	long long ans = dp.back();
	if(ans==Inf)ans = -1;
	cout<<ans<<endl;
	
	return 0;
}
0