結果

問題 No.137 貯金箱の焦り
ユーザー Min_25Min_25
提出日時 2016-07-10 12:27:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,660 bytes
コンパイル時間 1,235 ms
コンパイル使用メモリ 91,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 14:13:49
合計ジャッジ時間 2,603 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 42 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 20 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 17 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 17 ms
4,376 KB
testcase_19 AC 19 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx") // yukicoder
// #pragma GCC target ("sse4.2") // SPOJ, codechef

#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <tuple>

#define _rep(_1, _2, _3, _4, name, ...) name
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c))
#define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__)

using namespace std;

using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f80 = long double; 

u32 A[100];
u32 poly[50010];

const u32 MOD = 1234567891;

u32 add_mod(u32 a, u32 b) {
  return u32(a += b) >= MOD ? a - MOD : a;
}

// overlap も考慮してベクトル化される.
void vec_add(int n, u32* a, u32* b) {
  for (int i = n - 1; i >= 0; --i) {
    a[i] = add_mod(a[i], b[i]);
  }
}

void solve() {
  i64 N, M;
  while (~scanf("%lld %lld", &N, &M)) {
    i64 s = 0;
    rep(i, N) scanf("%u", &A[i]), s += A[i];
    sort(A, A + N);
    int t = 0;
    poly[t++] = 1;
    while (M) {
      fill(poly + t, poly + s + t, 0);
      rep(i, N) {
        vec_add(t, poly + A[i], poly);
        t += A[i];
      }
      int p = M & 1;
      M >>= 1;
      t = (t + 1 - p) >> 1;
      rep(i, t) poly[i] = poly[2 * i + p];
    }
    printf("%u\n", poly[0]);
  }
}

int main() {
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
0