結果
問題 | No.137 貯金箱の焦り |
ユーザー |
|
提出日時 | 2016-08-26 00:17:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 222 ms / 5,000 ms |
コード長 | 971 bytes |
コンパイル時間 | 902 ms |
コンパイル使用メモリ | 75,592 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 04:09:51 |
合計ジャッジ時間 | 2,787 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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; }