結果

問題 No.247 線形計画問題もどき
ユーザー motimoti
提出日時 2015-07-21 19:55:18
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 874 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 76,716 KB
実行使用メモリ 9,008 KB
最終ジャッジ日時 2023-09-22 20:57:46
合計ジャッジ時間 4,199 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>
#include <limits>

using namespace std;

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

typedef long long ll;

int N, C;
int A[101];

int constexpr invalid = std::numeric_limits<int>::max() / 6;

ll solve(int csum, int i, int xsum) {
  if(i == -1) {
    if(csum == 0) { return xsum; }
    else { return invalid; }
  }

  if(csum < 0) { return invalid; }

  ll ret = invalid;

  for(int x = csum / A[i]; x >= 0; x--) {
    ret = min(ret, solve(csum - A[i] * x, i-1, xsum + x));
  }

  return ret;
}

int main() {

  cin >> C >> N;
  rep(i, N) cin >> A[i];
  sort(A, A+N);
  auto ret = solve(C, N-1, 0);
  if(ret == invalid) {
    cout << -1 << endl;
  }
  else {
    cout << ret << endl;
  }

  return 0;
}
0