結果

問題 No.1929 Exponential Sequence
ユーザー asaringoasaringo
提出日時 2022-05-07 02:03:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,627 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 208,564 KB
実行使用メモリ 14,852 KB
最終ジャッジ日時 2023-10-12 04:23:57
合計ジャッジ時間 3,419 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 39 ms
14,264 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 1 ms
4,356 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 40 ms
14,852 KB
testcase_22 AC 25 ms
9,276 KB
testcase_23 AC 40 ms
14,652 KB
testcase_24 AC 18 ms
8,660 KB
testcase_25 AC 39 ms
13,848 KB
testcase_26 AC 41 ms
14,812 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
#define fast_input_output ios::sync_with_stdio(false); cin.tie(nullptr);
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

int n ;
ll s ;
ll A[10] ;
map<ll,ll> dp[5] , ep[5] ;
vector<ll> X , Y ;

int main(){
    fast_input_output
    cin >> n >> s ;
    rep(i,n) cin >> A[i] ;
    int m = n/2 ;
    dp[0][0] = 1 ;
    rep(i,m){
        for(auto it : dp[i]){
            ll val = it.first , cnt = it.second ;
            ll a = A[i] , x = A[i] ;
            while(val + a < s){
                dp[i+1][val+a] += cnt ;
                a *= x ;
            }
        }
    }
    for(auto it : dp[m]){
        ll val = it.first , cnt = it.second ;
        while(cnt > 0){
            X.push_back(val) ;
            cnt-- ;
        }
    }

    ep[0][0] = 1 ;
    rep(i,n-m){
        for(auto it : ep[i]){
            ll val = it.first , cnt = it.second ;
            ll a = A[i+m] , x = A[i+m] ;
            while(val + a < s){
                ep[i+1][val+a] += cnt ;
                a *= x ;
            }
        }
    }
    ll res = 0 ;
    for(auto it : ep[n-m]){
        ll val = it.first , cnt = it.second ;
        auto kt = upper_bound(X.begin(),X.end(),s-val) ;
        res += (ll)(kt - X.begin()) * cnt ;
    }
    cout << res << endl ;
}
0