結果
| 問題 | 
                            No.1929 Exponential Sequence
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-07-19 13:24:18 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 128 ms / 2,000 ms | 
| コード長 | 1,369 bytes | 
| コンパイル時間 | 1,316 ms | 
| コンパイル使用メモリ | 111,856 KB | 
| 最終ジャッジ日時 | 2025-02-15 15:43:23 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 24 | 
ソースコード
/*
サンプルに最大ケースがあるから全列挙っぽい
通り数を数えると無理
*/
#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;
int main(){
    int n;
    ll S;
    cin>>n>>S;
    vector<ll> a(n);
    vector<ll> a0,a1;
    for(int i=0;i<n;i++){
    
        cin>>a[i];
        if(i%2==0){
            a0.push_back(a[i]);
        }else{
            a1.push_back(a[i]);
        }
    }
    
 
    auto dfs=[&](auto f,ll s,int idx,const vector<ll>&a,vector<ll>& res)->void{
        if(idx==a.size()){
            res.push_back(s);
            return ;
        }
        //s-=x; 
        ll x=a[idx];
        while(s+x<=S){
            if(s+x>S) break;
            f(f,s+x,idx+1,a,res);
            
            x*=a[idx];
        }
    };
    vector<ll> res0,res1;
    dfs(dfs,0,0,a0,res0);
    dfs(dfs,0,0,a1,res1);
    sort(res0.begin(),res0.end());
    sort(res1.begin(),res1.end());
    ll ans=0;
    for(ll v:res0){
        auto it=upper_bound(res1.begin(),res1.end(),S-v);
        ll num=it-res1.begin();
        ans+=num;
    }
    cout<<ans<<endl;
    
}