結果

問題 No.1929 Exponential Sequence
ユーザー ぷらぷら
提出日時 2022-05-06 21:44:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 218,776 KB
実行使用メモリ 7,544 KB
最終ジャッジ日時 2023-10-12 04:20:08
合計ジャッジ時間 3,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 36 ms
7,544 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 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,348 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 36 ms
7,316 KB
testcase_22 AC 23 ms
6,100 KB
testcase_23 AC 36 ms
7,308 KB
testcase_24 AC 15 ms
5,168 KB
testcase_25 AC 35 ms
7,216 KB
testcase_26 AC 37 ms
7,408 KB
testcase_27 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n,S;
    cin >> n >> S;
    vector<int>a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    map<int,long long>mp;
    mp[0] = 1;
    for(int i = 0; i < n/2; i++) {
        map<int,long long>nmp;
        for(auto j:mp) {
            long long s = 1;
            for(int k = 1; ; k++) {
                s *= a[i];
                if(s+j.first > S) {
                    break;
                }
                nmp[s+j.first] += j.second;
            }
        }
        swap(mp,nmp);
    }
    map<int,long long>mp2;
    mp2[0] = 1;
    for(int i = 0; i < n-n/2; i++) {
        map<int,long long>nmp;
        for(auto j:mp2) {
            long long s = 1;
            for(int k = 1; ; k++) {
                s *= a[n/2+i];
                if(s+j.first > S) {
                    break;
                }
                nmp[s+j.first] += j.second;
            }
        }
        swap(mp2,nmp);
    }
    vector<int>id;
    vector<long long>sum;
    vector<pair<int,long long>>tmp;
    for(auto i:mp2) {
        tmp.push_back(i);
    }
    sort(tmp.begin(),tmp.end());
    id.resize(tmp.size());
    sum.resize(tmp.size());
    for(int i = 0; i < tmp.size(); i++) {
        id[i] = tmp[i].first;
        sum[i] = tmp[i].second;
        if(i) {
            sum[i] += sum[i-1];
        }
    }
    long long ans = 0;
    for(auto i:mp) {
        int it = upper_bound(id.begin(),id.end(),S-i.first)-id.begin();
        if(it) {
            ans += i.second*sum[it-1];
        }
    }
    cout << ans << endl;
}
0