結果

問題 No.1929 Exponential Sequence
ユーザー ruthenruthen
提出日時 2022-05-06 21:53:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 206,716 KB
実行使用メモリ 24,216 KB
最終ジャッジ日時 2023-10-12 04:20:55
合計ジャッジ時間 3,784 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 123 ms
23,812 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 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,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 123 ms
23,428 KB
testcase_22 AC 79 ms
14,540 KB
testcase_23 AC 122 ms
23,568 KB
testcase_24 AC 58 ms
12,484 KB
testcase_25 AC 122 ms
23,304 KB
testcase_26 AC 125 ms
24,216 KB
testcase_27 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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