結果

問題 No.247 線形計画問題もどき
ユーザー beetbeet
提出日時 2018-11-23 13:22:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 201,268 KB
実行使用メモリ 4,880 KB
最終ジャッジ日時 2023-09-21 18:54:33
合計ジャッジ時間 3,280 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,556 KB
testcase_01 AC 3 ms
4,552 KB
testcase_02 AC 30 ms
4,656 KB
testcase_03 AC 3 ms
4,616 KB
testcase_04 AC 4 ms
4,840 KB
testcase_05 AC 3 ms
4,652 KB
testcase_06 AC 3 ms
4,716 KB
testcase_07 AC 4 ms
4,620 KB
testcase_08 AC 4 ms
4,756 KB
testcase_09 AC 3 ms
4,864 KB
testcase_10 AC 3 ms
4,832 KB
testcase_11 AC 4 ms
4,612 KB
testcase_12 AC 3 ms
4,880 KB
testcase_13 AC 3 ms
4,620 KB
testcase_14 AC 4 ms
4,756 KB
testcase_15 AC 4 ms
4,756 KB
testcase_16 AC 3 ms
4,748 KB
testcase_17 AC 21 ms
4,880 KB
testcase_18 AC 4 ms
4,564 KB
testcase_19 AC 28 ms
4,572 KB
testcase_20 AC 30 ms
4,768 KB
testcase_21 AC 28 ms
4,704 KB
testcase_22 AC 29 ms
4,592 KB
testcase_23 AC 26 ms
4,624 KB
testcase_24 AC 25 ms
4,688 KB
testcase_25 AC 27 ms
4,696 KB
testcase_26 AC 10 ms
4,840 KB
testcase_27 AC 15 ms
4,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int c,n;
  cin>>c>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  
  const Int MAX = 2.1e5;
  const Int INF = 1e15;
  vector<Int> dp(MAX,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j+a[i]<MAX;j++)
      chmin(dp[j+a[i]],dp[j]+1);

  Int ans=dp[c]>=INF?-1:dp[c];
  cout<<ans<<endl;
  return 0;
}
0