結果

問題 No.137 貯金箱の焦り
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-08-25 23:30:48
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,802 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 162,364 KB
実行使用メモリ 22,304 KB
最終ジャッジ日時 2024-04-25 16:54:39
合計ジャッジ時間 41,002 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 964 ms
13,760 KB
testcase_01 AC 105 ms
6,812 KB
testcase_02 AC 410 ms
6,940 KB
testcase_03 AC 27 ms
6,940 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 2,552 ms
6,940 KB
testcase_08 AC 2,554 ms
6,940 KB
testcase_09 TLE -
testcase_10 AC 2,067 ms
6,940 KB
testcase_11 AC 28 ms
6,944 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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() {
        ll g[500 * N + 1];
        memset(g, 0, sizeof(g));
        g[0] = 1;
        for (int i = 0; i < N; i++) {
            for (int j = 500*N; j >= 0; j--) {
                if (j - A[i] >= 0) g[j] = (g[j] + g[j - A[i]]) % MOD;
            }
        }

        ll f[61][500 * N + 1];
        memset(f, 0, sizeof(f));
        for (ll x = 0; x <= 500*N; x++) {
            if ( (x & 1LL) == (M & 1LL) ) {
                f[0][x] = g[x];
            }
        }
        for (int p = 1; p <= 60; p++) {
            for (ll x = 0; x <= 500*N; x++) {
                if ( (M & (1LL<<p)) == ((x & 1LL)<<p) ) {
                    for (ll k = 0; k <= min(500LL*N, 2*x + 1); k++) {
                        f[p][x] = (f[p][x] + f[p - 1][k] * g[x - k / 2]) % MOD;
                    }
                }
            }
        }
        /*
        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