結果

問題 No.1929 Exponential Sequence
ユーザー hiragnhiragn
提出日時 2023-05-22 13:10:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 128,692 KB
実行使用メモリ 8,904 KB
最終ジャッジ日時 2023-08-23 22:18:58
合計ジャッジ時間 3,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 48 ms
8,852 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 45 ms
8,768 KB
testcase_22 AC 29 ms
6,968 KB
testcase_23 AC 45 ms
8,708 KB
testcase_24 AC 18 ms
5,728 KB
testcase_25 AC 44 ms
8,628 KB
testcase_26 AC 47 ms
8,904 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;
using ll = long long;


map<ll, ll> solve(vector<ll> a, const ll &s) {
    int n = a.size();
    // dp[i][j]: 0,a0~a_iからjを作る方法は何通りか
    vector<map<ll, ll>> dp(n + 1);
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        auto x = a[i];
        while (a[i] <= s) {
            for (const auto &[k, v]: dp[i]) {
                if (k + a[i] <= s) dp[i + 1][k + a[i]] += v;
            }
            a[i] *= x;
        }
    }
    return dp[n]; // 中身はmapで(和, その場合の数)のペア
}

int main() {
    int n;
    ll s;
    cin >> n >> s;

    vector<ll> a, b;
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        if (i < n / 2) {
            a.emplace_back(t);
        } else {
            b.emplace_back(t);
        }
    }

    auto c = solve(a, s);
    auto d = solve(b, s);

    // dの第2成分の累積和を計算
    for (auto i = d.begin(); i != d.end() and next(i) != d.end(); ++i) {
        next(i)->second += i->second;
    }

    ll ans = 0;
    for (const auto &[k, v]: c) {
        auto it = d.upper_bound(s - k);
        if (it == d.begin()) continue;
        else ans += prev(it)->second * v;
    }
    cout << ans << endl;
    return 0;
}
0