結果
問題 | No.247 線形計画問題もどき |
ユーザー |
|
提出日時 | 2020-09-10 11:04:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 523 bytes |
コンパイル時間 | 634 ms |
コンパイル使用メモリ | 71,812 KB |
最終ジャッジ日時 | 2025-01-14 09:13:20 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <iostream>#include <vector>constexpr int INF = 1 << 30;void solve() {int c, n;std::cin >> c >> n;std::vector<int> dp(c + 1, INF);dp[0] = 0;while (n--) {int a;std::cin >> a;for (int x = a; x <= c; ++x) {dp[x] = std::min(dp[x], dp[x - a] + 1);}}auto ans = dp[c];std::cout << (ans == INF ? -1 : ans) << "\n";}int main() {std::cin.tie(nullptr);std::ios::sync_with_stdio(false);solve();return 0;}