結果

問題 No.1929 Exponential Sequence
ユーザー milanis48663220milanis48663220
提出日時 2022-05-06 22:18:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,586 bytes
コンパイル時間 1,258 ms
コンパイル使用メモリ 127,692 KB
実行使用メモリ 8,872 KB
最終ジャッジ日時 2023-09-20 03:14:00
合計ジャッジ時間 4,188 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 271 ms
8,660 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 RE -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 RE -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 272 ms
8,656 KB
testcase_22 AC 170 ms
6,928 KB
testcase_23 AC 271 ms
8,652 KB
testcase_24 AC 120 ms
5,944 KB
testcase_25 AC 271 ms
8,696 KB
testcase_26 AC 273 ms
8,872 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const ll inf = 1e15;

ll pw(ll x, int r){
    ll ans = 1;
    for(int i = 0; i < r; i++){
        if(inf/x < ans) return inf;
        ans *= 2;
    }
    return ans;
}

void dfs(int i, vector<ll> &v, map<ll, ll> &mp, ll sum, ll s){
    if(i == v.size()){
        if(mp.count(sum)) mp[sum]++;
        else mp[sum] = 1;
        return;
    }
    ll x = 1;
    for(int r = 1; r <= 30; r++){
        if(s/v[i] < x) break;
        x *= v[i];
        dfs(i+1, v, mp, sum+x, s);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; ll s; cin >> n >> s;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    if(n == 1){
        int ans = 0;
        for(int r = 1; r <= 30; r++){
            if(pw(a[0], r) <= s) ans++;
        }
        cout << ans << endl;
        return -1;
    }
    vector<ll> vl, vr;
    for(int i = 0; i < n; i++){
        if(i*2 < n){
            vl.push_back(a[i]);
        }else{
            vr.push_back(a[i]);
        }
    }
    map<ll, ll> mpl, mpr;
    dfs(0, vl, mpl, 0, s);
    dfs(0, vr, mpr, 0, s);
    map<ll, ll> mp;
    ll sum = 0;
    for(auto [x, c]: mpr){
        sum += c;
        mp[x] = sum;
    }
    ll ans = 0;
    for(auto [x, c]: mpl){
        auto p = mp.upper_bound(s-x);
        if(p == mp.begin()) continue;
        p--;
        ans += c*p->second;
    }
    cout << ans << endl;
}
0