結果

問題 No.1929 Exponential Sequence
ユーザー SSRSSSRS
提出日時 2022-05-06 21:28:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 171,076 KB
実行使用メモリ 13,816 KB
最終ジャッジ日時 2023-10-12 04:19:22
合計ジャッジ時間 3,809 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 128 ms
13,816 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,356 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 122 ms
12,236 KB
testcase_22 AC 120 ms
12,372 KB
testcase_23 AC 122 ms
12,940 KB
testcase_24 AC 120 ms
12,192 KB
testcase_25 AC 123 ms
12,444 KB
testcase_26 AC 124 ms
11,872 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> &X, vector<int> &P, int S, int p){
  if (p == X.size()){
    P.push_back(S);
  } else {
    long long x = 1;
    while (true){
      x *= X[p];
      if (S + x > 1000000000){
        break;
      }
      dfs(X, P, S + x, p + 1);
    }
  }
}
int main(){
  int n, S;
  cin >> n >> S;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<int> X, Y;
  for (int i = 0; i < n / 2; i++){
    X.push_back(a[i]);
  }
  for (int i = n / 2; i < n; i++){
    Y.push_back(a[i]);
  }
  vector<int> P;
  dfs(X, P, 0, 0);
  vector<int> Q;
  dfs(Y, Q, 0, 0);
  sort(P.begin(), P.end());
  sort(Q.begin(), Q.end());
  int cnt = P.size();
  long long ans = 0;
  for (int i = 0; i < cnt; i++){
    ans += upper_bound(Q.begin(), Q.end(), S - P[i]) - Q.begin();
  }
  cout << ans << endl;
}
0