結果

問題 No.1929 Exponential Sequence
ユーザー monnumonnu
提出日時 2022-05-06 23:04:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 3,876 ms
コンパイル使用メモリ 231,196 KB
実行使用メモリ 23,200 KB
最終ジャッジ日時 2023-10-12 04:23:13
合計ジャッジ時間 5,862 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 127 ms
23,200 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,356 KB
testcase_21 AC 126 ms
22,884 KB
testcase_22 AC 82 ms
13,272 KB
testcase_23 AC 127 ms
22,672 KB
testcase_24 AC 56 ms
13,788 KB
testcase_25 AC 125 ms
22,236 KB
testcase_26 AC 130 ms
22,928 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000
#define MOD 998244353
#define MAX 300000

void dfs(vector<ll> &a,int i,ll sum,ll S,vector<ll> &A){
  if(i==a.size()){
    A.push_back(sum);
    return;
  }
  ll x=a[i];
  int k=1;
  while(sum+x<=S){
    dfs(a,i+1,sum+x,S,A);
    x*=a[i];
    k++;
  }
}

int main(){
  int n;
  ll S;
  cin>>n>>S;
  vector<ll> a,b;
  for(int i=0;i<n;i++){
    ll x;
    cin>>x;
    if(i%2==0){
      a.push_back(x);
    }else{
      b.push_back(x);
    }
  }

  vector<ll> A,B;
  dfs(a,0,0,S,A);
  dfs(b,0,0,S,B);
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());

  ll ans=0;
  for(int i=0;i<A.size();i++){
    int k=upper_bound(B.begin(),B.end(),S-A[i])-B.begin();
    ans+=(ll)k;
  }
  cout<<ans<<endl;
}
0