結果

問題 No.1782 ManyCoins
ユーザー PachicobuePachicobue
提出日時 2021-12-11 17:45:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 206,728 KB
実行使用メモリ 11,288 KB
最終ジャッジ日時 2023-09-27 05:59:39
合計ジャッジ時間 4,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 25 ms
7,472 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 30 ms
5,408 KB
testcase_17 AC 35 ms
6,452 KB
testcase_18 AC 37 ms
5,724 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 15 ms
4,508 KB
testcase_21 AC 7 ms
4,376 KB
testcase_22 AC 17 ms
4,512 KB
testcase_23 AC 44 ms
6,652 KB
testcase_24 AC 6 ms
11,232 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 39 ms
5,752 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 6 ms
11,184 KB
testcase_29 AC 34 ms
11,152 KB
testcase_30 AC 24 ms
11,288 KB
testcase_31 AC 32 ms
11,284 KB
testcase_32 AC 37 ms
11,240 KB
testcase_33 AC 53 ms
11,156 KB
testcase_34 AC 58 ms
11,180 KB
testcase_35 AC 71 ms
11,152 KB
testcase_36 AC 5 ms
4,436 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,720 KB
testcase_41 AC 3 ms
5,160 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 4 ms
9,720 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 3 ms
4,432 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 6 ms
11,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = long long;
constexpr int NMAX = 20;
constexpr int WMAX = 1000000;
constexpr i64 INF = 1LL << 60;
i64 dp[WMAX];
int Ws[NMAX];
int ws[NMAX];
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int N;
    i64 L;
    std::cin >> N >> L;
    for (int i = 0; i < N; i++) {
        std::cin >> Ws[i];
    }
    std::sort(Ws, Ws + N);
    const int W = Ws[0];
    for (int i = 1; i < N; i++) {
        ws[i] = Ws[i] % W;
    }

    std::fill(dp, dp + W, INF);
    dp[0] = 0;
    using P = std::pair<i64, int>;
    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 (int i = 1; i < N; i++) {
            int nw = (w + ws[i]);
            if (nw >= W) { nw -= W; }
            const i64 ndp = c + Ws[i];
            if (dp[nw] > ndp) {
                dp[nw] = ndp;
                Q.push({ndp, nw});
            }
        }
    }
    i64 ans = 0;
    for (int w = 0; w < W; w++) {
        if (dp[w] > L) { continue; }
        ans += (L - dp[w]) / W + 1;
    }
    std::cout << ans - 1 << "\n";
    return 0;
}
0