結果

問題 No.1929 Exponential Sequence
ユーザー SenioriousSeniorious
提出日時 2022-09-13 20:58:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 69,428 KB
実行使用メモリ 9,008 KB
最終ジャッジ日時 2023-08-20 22:23:14
合計ジャッジ時間 2,954 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 105 ms
8,808 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 102 ms
8,776 KB
testcase_22 AC 66 ms
7,528 KB
testcase_23 AC 101 ms
8,564 KB
testcase_24 AC 43 ms
6,664 KB
testcase_25 AC 100 ms
8,520 KB
testcase_26 AC 105 ms
9,008 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 8;
int n, s, a[N];
int s1[1000005], l1;
int s2[1000005], l2;

void dfs1(int i, int sum) {
  if (i == n / 2) {
    s1[++l1] = sum;
    return;
  }
  
  int x = 1;
  while (1ll * x * a[i] + sum <= s) {
    x *= a[i];
    dfs1(i + 1, sum + x);
  }
}

void dfs2(int i, int sum) {
  if (i == n) {
    s2[++l2] = sum;
    return;
  }

  int x = 1;
  while (1ll * x * a[i] + sum <= s) {
    x *= a[i];
    dfs2(i + 1, sum + x);
  }
}

int main() {
  cin >> n >> s;
  for (int i = 0; i != n; i++)
    cin >> a[i];
  dfs1(0, 0), dfs2(n / 2, 0);

  sort(s1 + 1, s1 + l1 + 1), sort(s2 + 1, s2 + l2 + 1);
  long long ans = 0;
  for (int i = 1, j = l2; i <= l1; i++) {
    while (s1[i] + s2[j] > s)
      j--;
    ans += j;
  }
  cout << ans << endl;
}
0