結果

問題 No.137 貯金箱の焦り
コンテスト
ユーザー iastm
提出日時 2026-07-12 03:37:13
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 100 ms / 5,000 ms
+ 441µs
コード長 773 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,409 ms
コンパイル使用メモリ 169,980 KB
実行使用メモリ 9,388 KB
最終ジャッジ日時 2026-07-12 03:37:35
合計ジャッジ時間 3,348 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <atcoder/modint>

using mint = atcoder::static_modint<1234567891>;

int main() {
    int N;
    int64_t M;
    std::cin >> N >> M;
    std::vector<int> A(N);
    for (int &a : A) std::cin >> a;

    int S = 0;
    for (int a : A) S += a;
    std::vector<mint> dp(S + 1);
    dp[0] = 1;

    while (M) {
        std::vector<mint> ndp(S * 2 + 1);
        for (int i = 0; i <= S; i++) ndp[i] = dp[i];
        for (int a : A) {
            for (int i = S * 2; i >= a; i--) {
                ndp[i] += ndp[i - a];
            }
        }
        int m = M & 1;
        for (int i = 0; (i << 1 | m) <= S * 2; i++) {
            dp[i] = ndp[i << 1 | m];
        }
        M >>= 1;
    }

    std::cout << dp[0].val() << std::endl;
}
0