結果
| 問題 | No.137 貯金箱の焦り |
| コンテスト | |
| ユーザー |
zjsdut
|
| 提出日時 | 2026-05-08 18:15:31 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,228 bytes |
| 記録 | |
| コンパイル時間 | 2,251 ms |
| コンパイル使用メモリ | 340,284 KB |
| 実行使用メモリ | 11,808 KB |
| 最終ジャッジ日時 | 2026-05-08 18:16:22 |
| 合計ジャッジ時間 | 12,821 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 TLE * 1 -- * 13 |
ソースコード
/**
* author: zjs
* created: 08.05.2026 16:52:47
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
unsigned long long m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
const int mod = 1234567891;
int s = accumulate(a.begin(), a.end(), 0);
vector<long long> f(s + 1); //背包 f[i][j]:a[1] ..., a[i] 中选一些,所选的数之和等于 j,有多少种选法
f[0] = 1;
for (int x : a)
for (int i = s; i >= x; i--)
f[i] = (f[i] + f[i - x]) % mod;
vector<long long> carry(s);
carry[0] = 1;
int len = bit_width(m);
for (int b = 0; b < len; b++) {
int bit = m >> b & 1;
vector<long long> n_carry(s);
for (int i = 0; i < s; i++)
for (int j = 0; j <= s; j++) {
if (((i + j) & 1) == bit) {
n_carry[(i + j) >> 1] += carry[i] * f[j] % mod;
}
}
for (int i = 0; i < s; i++)
n_carry[i] %= mod;
carry = n_carry;
}
cout << carry[0] << '\n';
}
zjsdut