結果

問題 No.137 貯金箱の焦り
ユーザー kimiyukikimiyuki
提出日時 2016-08-26 00:17:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 5,000 ms
コード長 971 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 76,100 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 17:00:21
合計ジャッジ時間 2,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 223 ms
6,940 KB
testcase_13 AC 18 ms
6,944 KB
testcase_14 AC 113 ms
6,940 KB
testcase_15 AC 99 ms
6,940 KB
testcase_16 AC 94 ms
6,940 KB
testcase_17 AC 32 ms
6,944 KB
testcase_18 AC 89 ms
6,944 KB
testcase_19 AC 107 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 51 ms
6,944 KB
testcase_22 AC 8 ms
6,944 KB
testcase_23 AC 7 ms
6,940 KB
testcase_24 AC 24 ms
6,940 KB
testcase_25 AC 65 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
const int mod = 1234567891;
int main() {
    int n; ll m; cin >> n >> m;
    vector<int> a(n); repeat (i,n) cin >> a[i];
    vector<ll> dp { 1, 1 };
    m *= 2;
    while (true) {
        for (int i = m % 2; i < dp.size(); i += 2) {
            dp[i/2] = dp[i];
        }
        m /= 2;
        if (m == 0) break;
        dp.resize(dp.size() / 2);
        dp.resize(dp.size() + whole(accumulate, a, 0) + 1);
        repeat (i,n) {
            repeat_reverse (j, dp.size() - a[i]) {
                dp[j + a[i]] += dp[j];
                dp[j + a[i]] %= mod;
            }
        }
    }
    cout << dp[0] << endl;
    return 0;
}
0