結果

問題 No.1929 Exponential Sequence
ユーザー ruthen71ruthen71
提出日時 2022-05-06 21:53:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 2,646 ms
コンパイル使用メモリ 201,704 KB
最終ジャッジ日時 2025-01-29 03:24:24
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, S;
    cin >> N >> S;
    V<ll> A(N);
    rep(i, N) cin >> A[i];
    ll N2 = N / 2;
    V<ll> A1 = {0}, A2 = {0};
    rep(i, N2) {
        V<ll> B;
        ll c = A[i];
        while (c <= S) {
            for (auto a : A1) {
                B.push_back(a + c);
            }
            c *= A[i];
        }
        A1 = B;
    }
    rep(i, N - N2) {
        V<ll> B;
        ll c = A[i + N2];
        while (c <= S) {
            for (auto a : A2) {
                B.push_back(a + c);
            }
            c *= A[i + N2];
        }
        A2 = B;
    }
    sort(A1.begin(), A1.end());
    sort(A2.begin(), A2.end());
    ll ans = 0;
    for (auto a : A1) {
        if (S - a >= 0) ans += upper_bound(A2.begin(), A2.end(), S - a) - A2.begin();
    }
    cout << ans << '\n';
    return 0;
}
0