結果

問題 No.1929 Exponential Sequence
ユーザー tnakao0123tnakao0123
提出日時 2022-05-08 21:30:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 57,444 KB
実行使用メモリ 7,824 KB
最終ジャッジ日時 2023-10-12 04:24:11
合計ジャッジ時間 2,494 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,096 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
5,092 KB
testcase_03 AC 141 ms
7,784 KB
testcase_04 AC 3 ms
5,080 KB
testcase_05 AC 2 ms
5,108 KB
testcase_06 AC 2 ms
5,064 KB
testcase_07 AC 2 ms
5,084 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
5,080 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
5,024 KB
testcase_15 AC 3 ms
5,236 KB
testcase_16 AC 3 ms
5,144 KB
testcase_17 AC 2 ms
5,024 KB
testcase_18 AC 2 ms
5,096 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 3 ms
5,096 KB
testcase_21 AC 139 ms
7,744 KB
testcase_22 AC 88 ms
6,856 KB
testcase_23 AC 138 ms
7,720 KB
testcase_24 AC 57 ms
6,284 KB
testcase_25 AC 135 ms
7,716 KB
testcase_26 AC 142 ms
7,824 KB
testcase_27 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1929.cc:  No.1929 Exponential Sequence - yukicoder
 */

#include<cstdio>
#include<map>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 8;
const int MAX_M = 30 * 30 * 30 * 30;

/* typedef */

typedef long long ll;
typedef map<int,int> mii;

/* global variables */

int as[MAX_N], bs[MAX_M], ss[MAX_M + 1];

/* subroutines */

void rec(int k, int n, int s, int sum, mii &scs) {
  if (k >= n) {
    scs[sum]++;
    return;
  }

  for (ll ea = as[k]; sum + ea <= s; ea *= as[k])
    rec(k + 1, n, s, sum + ea, scs);
}

/* main */

int main() {
  int n, s;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int h = n / 2;
  mii scs0, scs1;
  if (h > 0) rec(0, h, s, 0, scs0);
  if (h < n) rec(h, n, s, 0, scs1);

  if (h == 0) { printf("%d\n", (int)scs1.size()); return 0; }

  int m = 0;
  for (auto sc: scs1) {
    bs[m] = sc.first;
    ss[m + 1] = ss[m] + sc.second;
    m++;
  }

  ll sum = 0;
  for (auto sc: scs0) {
    int si = sc.first, ci = sc.second;
    int k = upper_bound(bs, bs + m, s - si) - bs;
    sum += (ll)ci * ss[k];
  }

  printf("%lld\n", sum);
  return 0;
}
0