結果
| 問題 |
No.137 貯金箱の焦り
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-08-25 23:30:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,802 bytes |
| コンパイル時間 | 2,181 ms |
| コンパイル使用メモリ | 161,532 KB |
| 実行使用メモリ | 20,736 KB |
| 最終ジャッジ日時 | 2024-11-08 04:03:30 |
| 合計ジャッジ時間 | 40,973 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 TLE * 5 -- * 13 |
ソースコード
#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;
}
izuru_matsuura