結果

問題 No.1782 ManyCoins
ユーザー Pachicobue
提出日時 2021-12-11 17:34:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,245 bytes
コンパイル時間 1,943 ms
コンパイル使用メモリ 199,580 KB
最終ジャッジ日時 2025-01-26 07:54:38
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using u64 = unsigned long long;
constexpr uint NMAX = 20;
constexpr uint WMAX = 1000000;
constexpr u64 INF = 1ULL << 60;
u64 dp[WMAX];
uint Ws[NMAX];
uint ws[NMAX];
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    uint N;
    u64 L;
    std::cin >> N >> L;
    for (uint i = 0; i < N; i++) {
        std::cin >> Ws[i];
    }
    std::sort(Ws, Ws + N);
    const uint W = Ws[0];
    for (uint i = 1; i < N; i++) {
        ws[i] = Ws[i] % W;
    }
    std::fill(dp, dp + W, INF);
    dp[0] = 0;
    using P = std::pair<u64, uint>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> Q;
    Q.push({0, 0});
    while (not Q.empty()) {
        const auto [c, w] = Q.top();
        Q.pop();
        if (dp[w] < c) { continue; }
        for (uint i = 1; i < N; i++) {
            uint nw = (w + ws[i]);
            if (nw >= W) { nw -= W; }
            const u64 ndp = c + Ws[i];
            if (dp[nw] > ndp) {
                Q.push({ndp, nw});
                dp[nw] = ndp;
            }
        }
    }
    u64 ans = 0;
    for (uint w = 0; w < W; w++) {
        if (dp[w] > L) { break; }
        ans += (L - dp[w]) / W + 1;
    }
    std::cout << ans - 1 << "\n";
    return 0;
}
0