結果

問題 No.137 貯金箱の焦り
コンテスト
ユーザー Min_25
提出日時 2015-12-08 22:12:13
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 956 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 468 ms
コンパイル使用メモリ 84,608 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-08 06:35:54
合計ジャッジ時間 1,998 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cassert>
#include <cstring>
#include <ctime>

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep3(i, m, n) for (int i = int(m); i < int(n); ++i)

using namespace std;
using int64 = long long;

const int64 MOD = 1234567891;

int A[50];
int64 poly[50010];

void solve() {
  int64 N, M;
  while (~scanf("%lld %lld", &N, &M)) {
    int64 s = 0;
    rep(i, N) scanf("%d", &A[i]), s += A[i];
    poly[0] = 1;
    int64 t = 1;
    while (M) {
      fill(poly + t, poly + s + t, 0);
      rep(i, N) {
        for(int j = t - 1; j >= 0; --j) {
          if (poly[j]) (poly[j + A[i]] += poly[j]) %= MOD;
        }
        t += A[i];
      }
      int p = M & 1;
      M >>= 1;
      t = (t + 1 - p) >> 1;
      rep(i, t) poly[i] = poly[2 * i + p];
    }
    printf("%lld\n", poly[0]);
  }
}

int main() {
  solve();
  return 0;
}
0