結果

問題 No.1929 Exponential Sequence
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-07-27 15:10:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 1,714 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 210,272 KB
実行使用メモリ 95,468 KB
最終ジャッジ日時 2024-04-15 02:42:55
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 200 ms
94,936 KB
testcase_04 AC 73 ms
44,692 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 7 ms
6,944 KB
testcase_12 AC 127 ms
88,544 KB
testcase_13 AC 72 ms
45,436 KB
testcase_14 AC 131 ms
88,820 KB
testcase_15 AC 130 ms
88,840 KB
testcase_16 AC 7 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 201 ms
93,528 KB
testcase_22 AC 177 ms
91,032 KB
testcase_23 AC 207 ms
93,660 KB
testcase_24 AC 165 ms
91,612 KB
testcase_25 AC 199 ms
95,468 KB
testcase_26 AC 200 ms
94,980 KB
testcase_27 AC 7 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<int> idx;

void _dfs(int N, int mi, int mx, vector<vector<int>> &A){
    if (idx.size() == N){
        A.push_back(idx);
        return;
    }
    else{
        for (int i = mi; i <= mx; i++){
            idx.push_back(i);
            _dfs(N, mi, mx, A);
            idx.pop_back();
        }
    }
}

//mi~mxのN重ループを返す。
vector<vector<int>> nested_loop(int N, int mi, int mx){
    vector<vector<int>> res;
    _dfs(N, mi, mx, res);
    return res;
}

int main(){

    ll N, S, x, l, r, sm, ans=0;
    cin >> N >> S;
    vector<ll> a(N), b(N);
    vector<vector<ll>> c(N, vector<ll>(30));
    for (int i=0; i<N; i++){
        cin >> a[i];
        x = 1;
        while (x * a[i] <= S){
            x *= a[i];
            b[i]++;
        }
        c[i][0] = 1;
        for (int j=1; j<=b[i]; j++) c[i][j] = c[i][j-1] * a[i];
    }

    l = (N+1)/2, r=N-l;
    vector<ll> w;
    vector<vector<int>> v = nested_loop(l, 1, 29);

    for (auto &vv : v){
        sm = 0;
        for (int i=0; i<l; i++){
            if (b[i] < vv[i]){
                sm = -1;
                break;
            }
            sm += c[i][vv[i]];
        }
        if (sm <= S && sm >= 0) w.push_back(sm);
    }
    sort(w.begin(), w.end());

    v = nested_loop(r, 1, 29);
    for (auto &vv : v){
        sm = 0;
        for (int i=0; i<r; i++){
            if (b[i+l] < vv[i]){
                sm = -1;
                break;
            }
            sm += c[i+l][vv[i]];
        }
        if (sm <= S && sm >= 0){
            ans += upper_bound(w.begin(), w.end(), S-sm) - w.begin();
        }
    }

    cout << ans << endl;

    return 0;
}
0