結果

問題 No.137 貯金箱の焦り
ユーザー kroton
提出日時 2015-01-22 13:48:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 227 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 161,620 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-07 23:02:53
合計ジャッジ時間 3,433 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MOD = 1234567891ll;

ll solve(const vector<int>& A, ll M){
    int S = 0;
    for(int x : A)
        S += x;
    
    S *= 2;
    
    vector<ll> dp(S + 10, 0);
    dp[0] = 1;
    
    for(;M;M>>=1){
        for(int x : A){
            for(int i=S-x;i>=0;i--){
                dp[i+x] += dp[i];
                dp[i+x] %= MOD;
            }
        }
        
        vector<ll> ndp(S + 10, 0);
        for(int i=0;i<=S;i++){
            if((i ^ M) & 1)
                continue;
            
            ndp[i >> 1] += dp[i];
            ndp[i >> 1] %= MOD;
        }
        
        dp.swap(ndp);
    }
    
    return dp[0];
}

int main(){
    int N; ll M;
    
    cin >> N >> M;
    
    vector<int> A(N);
    for(int i=0;i<N;i++)
        cin >> A[i];
    
    cout << solve(A, M) << endl;
    return 0;
}
0