結果

問題 No.137 貯金箱の焦り
ユーザー Min_25Min_25
提出日時 2015-12-08 22:12:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 197 ms / 5,000 ms
コード長 956 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 63,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 18:20:39
合計ジャッジ時間 2,296 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 197 ms
4,380 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 91 ms
4,376 KB
testcase_15 AC 80 ms
4,376 KB
testcase_16 AC 76 ms
4,380 KB
testcase_17 AC 26 ms
4,376 KB
testcase_18 AC 72 ms
4,380 KB
testcase_19 AC 85 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 41 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 20 ms
4,376 KB
testcase_25 AC 52 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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