結果

問題 No.1782 ManyCoins
ユーザー PachicobuePachicobue
提出日時 2021-12-11 17:00:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,659 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 200,884 KB
実行使用メモリ 12,656 KB
最終ジャッジ日時 2023-09-27 05:02:29
合計ジャッジ時間 5,692 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,484 KB
testcase_01 AC 2 ms
5,448 KB
testcase_02 AC 2 ms
5,572 KB
testcase_03 AC 2 ms
5,424 KB
testcase_04 AC 2 ms
5,364 KB
testcase_05 AC 2 ms
5,472 KB
testcase_06 AC 2 ms
5,440 KB
testcase_07 AC 2 ms
5,524 KB
testcase_08 AC 3 ms
5,356 KB
testcase_09 AC 2 ms
5,576 KB
testcase_10 AC 2 ms
5,428 KB
testcase_11 AC 2 ms
5,432 KB
testcase_12 AC 3 ms
5,452 KB
testcase_13 AC 23 ms
11,224 KB
testcase_14 AC 70 ms
11,344 KB
testcase_15 AC 42 ms
10,300 KB
testcase_16 AC 50 ms
11,208 KB
testcase_17 AC 70 ms
11,388 KB
testcase_18 AC 49 ms
11,400 KB
testcase_19 AC 2 ms
5,564 KB
testcase_20 AC 66 ms
11,532 KB
testcase_21 AC 74 ms
11,360 KB
testcase_22 AC 94 ms
10,276 KB
testcase_23 AC 82 ms
11,160 KB
testcase_24 AC 16 ms
9,404 KB
testcase_25 AC 92 ms
10,592 KB
testcase_26 AC 40 ms
10,088 KB
testcase_27 AC 108 ms
11,376 KB
testcase_28 AC 16 ms
9,272 KB
testcase_29 AC 21 ms
12,656 KB
testcase_30 AC 22 ms
11,968 KB
testcase_31 AC 25 ms
11,760 KB
testcase_32 AC 26 ms
11,924 KB
testcase_33 AC 34 ms
11,508 KB
testcase_34 AC 42 ms
11,308 KB
testcase_35 AC 71 ms
11,448 KB
testcase_36 AC 19 ms
9,048 KB
testcase_37 AC 16 ms
9,112 KB
testcase_38 AC 16 ms
9,340 KB
testcase_39 AC 7 ms
6,500 KB
testcase_40 AC 15 ms
9,120 KB
testcase_41 AC 13 ms
8,540 KB
testcase_42 AC 15 ms
8,892 KB
testcase_43 AC 12 ms
8,264 KB
testcase_44 AC 17 ms
9,468 KB
testcase_45 AC 14 ms
8,684 KB
testcase_46 AC 3 ms
5,868 KB
testcase_47 AC 3 ms
5,936 KB
testcase_48 AC 2 ms
5,484 KB
testcase_49 AC 2 ms
5,356 KB
testcase_50 AC 17 ms
9,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
constexpr int NMAX = 20;
constexpr int WMAX = 1000000;
struct Deq
{
    Deq() {}
    int front() const
    {
        return BUF[head];
    }
    bool isEmpty() const
    {
        return (head == tail);
    }
    void pushFront(int v)
    {
        BUF[--head] = v;
    }
    void pushBack(int v)
    {
        BUF[tail++] = v;
    }
    void popFront()
    {
        head++;
    }
    int BUF[2 * WMAX + 1];
    int head = WMAX, tail = WMAX;
};
constexpr int INF = 1 << 30;
int dp[WMAX];
int Ws[NMAX];
int main()
{
    using i64 = long long;
    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, std::greater<int>{});
    const int W = Ws[0];
    std::fill(dp, dp + W, INF);
    dp[0] = 0;
    Deq Q;
    Q.pushFront(0);
    while (not Q.isEmpty()) {
        const int w = Q.front();
        Q.popFront();
        for (int i = 1; i < N; i++) {
            int nw = w + Ws[i];
            if (nw >= W) {
                nw -= W;
                if (dp[nw] > dp[w] + 1) {
                    dp[nw] = dp[w] + 1;
                    Q.pushBack(nw);
                }
            } else {
                if (dp[nw] > dp[w]) {
                    dp[nw] = dp[w];
                    Q.pushFront(nw);
                }
            }
        }
    }
    i64 ans = 0;
    for (int w = 0; w < W; w++) {
        if (w > L) { break; }
        const i64 l = (L - w) / W;
        if (l < dp[w]) { continue; }
        ans += l - dp[w] + 1;
    }
    std::cout << ans - 1 << "\n";
    return 0;
}
0