結果

問題 No.1929 Exponential Sequence
ユーザー merom686merom686
提出日時 2022-05-06 23:02:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 2,098 ms
コンパイル使用メモリ 205,860 KB
実行使用メモリ 9,432 KB
最終ジャッジ日時 2023-10-12 04:23:07
合計ジャッジ時間 3,900 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 93 ms
9,432 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 93 ms
9,232 KB
testcase_22 AC 60 ms
7,388 KB
testcase_23 AC 92 ms
9,364 KB
testcase_24 AC 41 ms
6,252 KB
testcase_25 AC 90 ms
9,352 KB
testcase_26 AC 95 ms
9,316 KB
testcase_27 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int u;
void dfs(int *a, int *b, int *c, int d, int s, int r) {
    int t = 1;
    for (int i = 1; i < c[d]; i++) {
        t *= a[d];
        if (r + t > s) break;
        if (d == 0) {
            b[u++] = r + t;
        } else {
            dfs(a, b, c, d - 1, s, r + t);
        }
    }
}

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

    int a[8], c[8];
    for (int i = 0; i < n; i++) {
        cin >> a[i];

        ll t = 1;
        for (int j = 1;; j++) {
            t *= a[i];
            if (t > s) {
                c[i] = j;
                break;
            }
        }
    }

    int m[2];
    m[0] = min(n, 4);
    m[1] = n - m[0];

    vector<int> b[2];
    for (int h = 0; h < 2; h++) {
        int t = 1;
        for (int i = 0; i < m[h]; i++) {
            t *= c[i + h * m[0]];
        }
        b[h].resize(t, s + 1);
        if (m[h] == 0) {
            b[h][0] = 0;
        } else {
            u = 0;
            dfs(a + h * m[0], &b[h][0], c + h * m[0], m[h] - 1, s, 0);
        }
        sort(b[h].begin(), b[h].end());
    }

    ll r = 0;
    int k = b[0].size(), j = b[1].size() - 1;
    for (int i = 0; i < k; i++) {
        while (j >= 0 && b[0][i] + b[1][j] > s) j--;
        r += j + 1;
    }
    //cout << b[0].size() << ' ' << b[1].size() << endl;
    cout << r << endl;

    return 0;
}
0