結果

問題 No.247 線形計画問題もどき
コンテスト
ユーザー sten_san
提出日時 2020-12-28 14:51:47
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 9 ms / 2,000 ms
+ 503µs
コード長 776 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,351 ms
コンパイル使用メモリ 220,300 KB
実行使用メモリ 9,788 KB
最終ジャッジ日時 2026-10-15 02:39:27
合計ジャッジ時間 3,080 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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