結果

問題 No.137 貯金箱の焦り
ユーザー なおなお
提出日時 2015-01-26 06:10:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 220 ms / 5,000 ms
コード長 967 bytes
コンパイル時間 1,451 ms
コンパイル使用メモリ 157,832 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 11:41:58
合計ジャッジ時間 3,934 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 20 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 23 ms
5,376 KB
testcase_05 AC 10 ms
5,376 KB
testcase_06 AC 23 ms
5,376 KB
testcase_07 AC 16 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 23 ms
5,376 KB
testcase_10 AC 14 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 218 ms
5,376 KB
testcase_13 AC 32 ms
5,376 KB
testcase_14 AC 220 ms
5,376 KB
testcase_15 AC 186 ms
5,376 KB
testcase_16 AC 189 ms
5,376 KB
testcase_17 AC 111 ms
5,376 KB
testcase_18 AC 180 ms
5,376 KB
testcase_19 AC 218 ms
5,376 KB
testcase_20 AC 12 ms
5,376 KB
testcase_21 AC 139 ms
5,376 KB
testcase_22 AC 49 ms
5,376 KB
testcase_23 AC 41 ms
5,376 KB
testcase_24 AC 97 ms
5,376 KB
testcase_25 AC 164 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);++(i))
const int MOD = 1234567891;

const ll MAX = 2*50*500;
ll N,M,A[55],dp[50005];

int main(){
    cin >> N >> M;
    REP(j,N) cin >> A[j];

#ifdef _DEBUG
    int i = 0;
    ll L = 0;
#endif

    dp[0] = 1;
    while(M){
        REP(j,N) for(int k = MAX; k >= A[j]; k--){
            dp[k] = (dp[k] + dp[k-A[j]]) % MOD;
        }
        int b = M % 2;
        REP(j,MAX/2+1) dp[j] = dp[j*2+b];
        FOR(j,MAX/2+1,MAX+1) dp[j] = 0;

#ifdef _DEBUG
        L |= (ll)b << i;
        fprintf(stderr, "----\n");
        REP(j,min(MAX,M/2)+1){
            if(dp[j] > 0)
                fprintf(stderr,"dp[%lld] = %lld\n", ((ll)j<<(i+1))+L, dp[j]);
        }
        i++;
#endif
        M /= 2;
    }
    cout << dp[0] << endl;

    return 0;
}
0