結果

問題 No.137 貯金箱の焦り
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-08-26 00:07:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,129 ms / 5,000 ms
コード長 2,075 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 152,948 KB
実行使用メモリ 47,644 KB
最終ジャッジ日時 2023-08-07 22:40:40
合計ジャッジ時間 11,847 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
6,436 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 7 ms
5,440 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 95 ms
12,276 KB
testcase_05 AC 95 ms
12,228 KB
testcase_06 AC 95 ms
12,296 KB
testcase_07 AC 43 ms
8,984 KB
testcase_08 AC 43 ms
8,856 KB
testcase_09 AC 95 ms
12,412 KB
testcase_10 AC 35 ms
8,260 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1,109 ms
47,512 KB
testcase_13 AC 1,118 ms
47,612 KB
testcase_14 AC 1,129 ms
47,644 KB
testcase_15 AC 827 ms
39,024 KB
testcase_16 AC 877 ms
40,260 KB
testcase_17 AC 282 ms
21,432 KB
testcase_18 AC 801 ms
38,056 KB
testcase_19 AC 1,107 ms
46,628 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 443 ms
27,220 KB
testcase_22 AC 43 ms
8,896 KB
testcase_23 AC 35 ms
8,260 KB
testcase_24 AC 222 ms
18,796 KB
testcase_25 AC 637 ms
33,680 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