結果

問題 No.1929 Exponential Sequence
ユーザー 👑 colognecologne
提出日時 2022-05-10 15:26:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 890 bytes
コンパイル時間 3,012 ms
コンパイル使用メモリ 254,004 KB
実行使用メモリ 13,500 KB
最終ジャッジ日時 2023-10-12 04:24:24
合計ジャッジ時間 4,717 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 113 ms
12,836 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 109 ms
12,920 KB
testcase_22 AC 71 ms
8,848 KB
testcase_23 AC 110 ms
12,768 KB
testcase_24 AC 47 ms
7,344 KB
testcase_25 AC 108 ms
12,504 KB
testcase_26 AC 112 ms
13,500 KB
testcase_27 AC 2 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 &a : A)
        cin >> a;

    auto m = [&](vector<int> A)
    {
        vector<int> V = {0};
        for (int a : A)
        {
            vector<int> W;
            int x = 1;
            while ((long)x * a <= S)
            {
                x *= a;
                for (int b : V)
                    if (x + b <= S)
                        W.push_back(x + b);
            }
            V = W;
        }
        return V;
    };

    auto X = m(vector<int>(A.begin(), A.begin() + N / 2));
    auto Y = m(vector<int>(A.begin() + N / 2, A.end()));
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    long ans = 0;
    for(int x: X)
        ans += distance(Y.begin(), upper_bound(Y.begin(), Y.end(), S-x));

    cout << ans << endl;

    return 0;
}
0