結果

問題 No.137 貯金箱の焦り
コンテスト
ユーザー zjsdut
提出日時 2026-05-08 20:26:26
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 165 ms / 5,000 ms
コード長 962 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,311 ms
コンパイル使用メモリ 334,388 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-05-08 20:26:31
合計ジャッジ時間 4,627 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/**
 *    author:  zjs
 *    created: 08.05.2026 16:52:47
**/
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    unsigned long long m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    const int mod = 1234567891;

    int s = accumulate(a.begin(), a.end(), 0);
    vector<long long> carry(2 * s);
    carry[0] = 1;

    int len = bit_width(m);
    for (int b = 0; b < len; b++) {
        int bit = m >> b & 1;
        // 01背包
        for (int x : a) {
            for (int i = 2 * s - 1; i >= x; i--)
                carry[i] = (carry[i] + carry[i - x]) % mod; 
        }
        // 进位
        for (int i = 0; i < s; i++)
            carry[i] = carry[2 * i + bit];
        for (int i = s; i < 2 * s; i++)
            carry[i] = 0;
    }
    cout << carry[0] << '\n';
}
0