結果

問題 No.1929 Exponential Sequence
ユーザー HIcoderHIcoder
提出日時 2023-07-19 13:24:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 1,147 ms
コンパイル使用メモリ 117,180 KB
実行使用メモリ 22,712 KB
最終ジャッジ日時 2023-10-19 15:50:16
合計ジャッジ時間 3,294 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 116 ms
22,712 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 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,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 114 ms
22,712 KB
testcase_22 AC 73 ms
13,468 KB
testcase_23 AC 113 ms
22,712 KB
testcase_24 AC 50 ms
12,676 KB
testcase_25 AC 114 ms
22,712 KB
testcase_26 AC 116 ms
22,712 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
サンプルに最大ケースがあるから全列挙っぽい
通り数を数えると無理
*/
#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;

    


}
0