結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2015-10-10 14:33:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 501 bytes |
コンパイル時間 | 1,151 ms |
コンパイル使用メモリ | 163,340 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-07 11:12:05 |
合計ジャッジ時間 | 2,162 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include "bits/stdc++.h"using namespace std;#define REP(i, n) for(int i=0; i<(n); i++)#define RREP(i, n) for(int i=(n-1); i>=0; i--)#define ALL(a) (a).begin(),(a).end()int N,C;int dp[511111];signed main(){cin>>C>>N;vector<int> A(N);REP(i,N) cin >> A[i];sort(ALL(A));REP(j,C+1) dp[j] = 1e9;dp[0] = 0;REP(i,N) REP(j,C+1) {int a = A[i];dp[j+a] = min(dp[j+a], 1 + dp[j]);}cout << (dp[C] < 1e9 ? dp[C] : -1) << endl;return 0;}