結果
問題 |
No.247 線形計画問題もどき
|
ユーザー |
![]() |
提出日時 | 2020-12-28 14:39:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 1,990 ms |
コンパイル使用メモリ | 200,600 KB |
最終ジャッジ日時 | 2025-01-17 07:53:32 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> using vec = vector<T>; template <typename T> using vvec = vec<vec<T>>; template <typename T> using lqueue = priority_queue<T, vector<T>, greater<T>>; template <typename T> using gqueue = priority_queue<T, vector<T>, less<T>>; int main() { constexpr int inf = INT_MAX / 4; int c, n; cin >> c >> n; vec<int> a(n); for (auto &e : a) cin >> e; vec<int> dist(c + 1, inf); lqueue<array<int, 2>> que; dist[0] = 0; que.push({ 0, 0 }); while (!que.empty()) { auto [cost, vertex] = que.top(); que.pop(); for (auto d : a) { int next = vertex + d; if (c < next || dist[next] <= dist[vertex] + 1) continue; dist[next] = dist[vertex] + 1; que.push({ dist[next], next }); } } if (dist[c] == inf) { cout << -1 << endl; } else { cout << dist[c] << endl; } }