結果

問題 No.247 線形計画問題もどき
ユーザー oxyshoweroxyshower
提出日時 2019-03-07 19:03:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 166,164 KB
実行使用メモリ 83,292 KB
最終ジャッジ日時 2023-09-21 18:59:31
合計ジャッジ時間 3,402 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
83,068 KB
testcase_01 AC 25 ms
83,108 KB
testcase_02 AC 51 ms
83,064 KB
testcase_03 AC 25 ms
83,116 KB
testcase_04 AC 25 ms
83,040 KB
testcase_05 AC 24 ms
83,068 KB
testcase_06 AC 24 ms
83,056 KB
testcase_07 AC 26 ms
83,040 KB
testcase_08 AC 25 ms
83,116 KB
testcase_09 AC 25 ms
83,040 KB
testcase_10 AC 25 ms
83,236 KB
testcase_11 AC 24 ms
83,236 KB
testcase_12 AC 25 ms
83,112 KB
testcase_13 AC 25 ms
83,236 KB
testcase_14 AC 25 ms
83,064 KB
testcase_15 AC 24 ms
83,232 KB
testcase_16 AC 25 ms
83,036 KB
testcase_17 AC 28 ms
83,064 KB
testcase_18 AC 25 ms
83,056 KB
testcase_19 AC 33 ms
83,060 KB
testcase_20 AC 36 ms
83,116 KB
testcase_21 AC 25 ms
83,120 KB
testcase_22 AC 28 ms
83,068 KB
testcase_23 AC 27 ms
83,124 KB
testcase_24 AC 36 ms
83,204 KB
testcase_25 AC 32 ms
83,120 KB
testcase_26 AC 26 ms
83,236 KB
testcase_27 AC 27 ms
83,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

const int MOD = 1e9+7;
const int INF = 1LL << 60;

int dp[101][101010];

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int C,N; cin >> C >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  fill(dp[0],dp[100]+101010,INF);
  dp[0][0] = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= C; j++){
      if(j-a[i] >= 0){
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+1);
      }
      else dp[i+1][j] = dp[i][j];
    }
  }
  if(dp[N][C] == INF) cout << -1 << endl;
  else cout << dp[N][C] << endl;

  return 0;
}
0