結果

問題 No.247 線形計画問題もどき
ユーザー sten_san
提出日時 2020-12-28 14:51:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 198,072 KB
最終ジャッジ日時 2025-01-17 07:53:42
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#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() {
    int c, n; cin >> c >> n;
    vec<int> a(n);
    for (auto &e : a) cin >> e;

    vec<int> dist(c + 1, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int vtx = que.front(); que.pop();

        for (auto d : a) {
            int next = vtx + d;
            if (c < next || dist[next] != -1) continue;
            dist[next] = dist[vtx] + 1;
            que.push(next);
        }
    }

    cout << dist[c] << endl;
}

0