結果

問題 No.1782 ManyCoins
ユーザー PachicobuePachicobue
提出日時 2021-12-11 16:43:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,820 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 201,692 KB
実行使用メモリ 11,328 KB
最終ジャッジ日時 2023-09-27 04:41:52
合計ジャッジ時間 5,799 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,284 KB
testcase_01 AC 5 ms
7,384 KB
testcase_02 AC 5 ms
7,292 KB
testcase_03 AC 5 ms
7,360 KB
testcase_04 AC 5 ms
7,328 KB
testcase_05 AC 5 ms
7,284 KB
testcase_06 AC 5 ms
7,396 KB
testcase_07 AC 5 ms
7,292 KB
testcase_08 AC 4 ms
7,284 KB
testcase_09 AC 5 ms
7,280 KB
testcase_10 AC 5 ms
7,288 KB
testcase_11 AC 5 ms
7,344 KB
testcase_12 AC 5 ms
7,304 KB
testcase_13 AC 25 ms
9,100 KB
testcase_14 AC 80 ms
10,900 KB
testcase_15 AC 47 ms
9,744 KB
testcase_16 AC 57 ms
10,392 KB
testcase_17 AC 82 ms
10,544 KB
testcase_18 AC 53 ms
10,648 KB
testcase_19 AC 5 ms
7,344 KB
testcase_20 AC 71 ms
10,024 KB
testcase_21 AC 79 ms
10,852 KB
testcase_22 AC 104 ms
10,420 KB
testcase_23 AC 92 ms
10,452 KB
testcase_24 AC 16 ms
7,300 KB
testcase_25 AC 98 ms
10,660 KB
testcase_26 AC 47 ms
11,260 KB
testcase_27 AC 116 ms
10,792 KB
testcase_28 AC 16 ms
7,292 KB
testcase_29 AC 21 ms
11,240 KB
testcase_30 AC 23 ms
11,228 KB
testcase_31 AC 25 ms
11,240 KB
testcase_32 AC 27 ms
11,236 KB
testcase_33 AC 36 ms
11,184 KB
testcase_34 AC 46 ms
11,180 KB
testcase_35 AC 69 ms
11,328 KB
testcase_36 AC 19 ms
7,548 KB
testcase_37 AC 16 ms
7,540 KB
testcase_38 AC 16 ms
7,296 KB
testcase_39 AC 8 ms
7,284 KB
testcase_40 AC 15 ms
7,288 KB
testcase_41 AC 13 ms
7,288 KB
testcase_42 AC 15 ms
7,288 KB
testcase_43 AC 13 ms
7,288 KB
testcase_44 AC 16 ms
7,348 KB
testcase_45 AC 14 ms
7,516 KB
testcase_46 AC 6 ms
7,332 KB
testcase_47 AC 5 ms
7,336 KB
testcase_48 AC 5 ms
7,284 KB
testcase_49 AC 5 ms
7,280 KB
testcase_50 AC 16 ms
7,336 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)
    {
        --head;
        if (head < 0) { head += (WMAX + 1); }
        BUF[head] = v;
    }
    void pushBack(int v)
    {
        BUF[tail++] = v;
        if (tail == WMAX + 1) { tail -= (WMAX + 1); }
    }
    void popFront()
    {
        head++;
        if (head == WMAX + 1) { head -= (WMAX + 1); }
    }
    int BUF[WMAX + 1];
    int head = 0, tail = 0;
};
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 + WMAX, 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