結果

問題 No.137 貯金箱の焦り
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-08-26 00:07:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,025 ms / 5,000 ms
コード長 2,075 bytes
コンパイル時間 1,741 ms
コンパイル使用メモリ 167,808 KB
実行使用メモリ 47,812 KB
最終ジャッジ日時 2024-04-25 17:00:05
合計ジャッジ時間 10,563 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 92 ms
12,328 KB
testcase_05 AC 92 ms
12,452 KB
testcase_06 AC 92 ms
12,320 KB
testcase_07 AC 41 ms
8,968 KB
testcase_08 AC 41 ms
8,840 KB
testcase_09 AC 92 ms
12,324 KB
testcase_10 AC 34 ms
8,344 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1,022 ms
47,812 KB
testcase_13 AC 1,018 ms
47,680 KB
testcase_14 AC 1,025 ms
47,808 KB
testcase_15 AC 735 ms
39,216 KB
testcase_16 AC 775 ms
40,352 KB
testcase_17 AC 263 ms
21,556 KB
testcase_18 AC 718 ms
38,272 KB
testcase_19 AC 1,023 ms
46,412 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 411 ms
27,220 KB
testcase_22 AC 42 ms
8,968 KB
testcase_23 AC 35 ms
8,472 KB
testcase_24 AC 215 ms
18,920 KB
testcase_25 AC 602 ms
33,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N; ll M;
    vector<int> A;
    void input() {
        cin >> N >> M;
        A.resize(N); cin >> A;
    }

    const ll MOD = 1234567891LL;

    void solve() {
        vector<ll> g(1000*N + 1, 0);
        g[0] = 1;
        for (int i = 0; i < N; i++) {
            for (int j = 1000*N; j >= 0; j--) {
                if (j - A[i] >= 0) g[j] = (g[j] + g[j - A[i]]) % MOD;
            }
        }

        vector<vector<ll>> f(61, vector<ll>(1000*N + 1, 0));
        for (ll x = 0; x <= 1000*N; x++) {
            if ( (x & 1LL) == (M & 1LL) ) {
                f[0][x] = g[x];
            }
        }
        for (int p = 1; p <= 60; p++) {
            vector<vector<ll>> h(N + 1, vector<ll>(1000*N + 1, 0));
            for (ll x = 0; x <= 1000*N; x++) {
                h[0][x/2] += f[p - 1][x];
            }
            for (int k = 1; k <= N; k++) {
                for (ll x = 0; x <= 1000*N; x++) {
                    h[k][x] = h[k - 1][x];
                    if (x - A[k-1] >= 0) h[k][x] = (h[k][x] + h[k-1][x - A[k-1]]) % MOD;
                }
            }
            for (ll x = 0; x <= 1000*N; x++) {
                if ( (M & (1LL<<p)) == ((x & 1LL)<<p) ) {
                    f[p][x] = h[N][x];
                }
            }
        }
        /*
        for (int p = 0; p < 5; p++) {
            for (ll x = 0; x < 10; x++) {
                cout << f[p][x] << " ";
            }
            cout << endl;
        }
        */
        cout << f[60][0] << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0