結果

問題 No.137 貯金箱の焦り
ユーザー t98slidert98slider
提出日時 2022-11-12 13:38:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 670 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 168,916 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 05:19:58
合計ジャッジ時間 3,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 132 ms
4,348 KB
testcase_13 AC 12 ms
4,348 KB
testcase_14 AC 69 ms
4,352 KB
testcase_15 AC 60 ms
4,348 KB
testcase_16 AC 58 ms
4,352 KB
testcase_17 AC 20 ms
4,348 KB
testcase_18 AC 55 ms
4,348 KB
testcase_19 AC 66 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 31 ms
4,348 KB
testcase_22 AC 5 ms
4,352 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 15 ms
4,348 KB
testcase_25 AC 40 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const unsigned int MOD = 1234567891;

int main(){
    int N;
    ll M;
    cin >> N >> M;
    vector<int> A(N);
    for(auto &&v:A)cin >> v;
    int Asum = accumulate(A.begin(), A.end(), 0);
    vector<unsigned int> dp(2 * Asum);
    dp[0] = 1;
    while(M){
        for(int i = 0; i < N; i++){
            for(int x = 2 * Asum - 1; x >= A[i]; x--){
                if((dp[x] += dp[x - A[i]]) >= MOD)dp[x] -= MOD;
            }
        }
        for(int x = 0; x < Asum; x++)dp[x] = dp[x << 1 | (M & 1)];
        fill(dp.begin() + Asum, dp.end(), 0);
        M >>= 1;
    }
    cout << dp[0] << '\n';
}
0