結果

問題 No.1731 Product of Subsequence
ユーザー nebukuro09nebukuro09
提出日時 2021-11-05 23:26:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 795 ms / 2,000 ms
コード長 1,575 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 183,508 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 17:35:40
合計ジャッジ時間 9,990 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 755 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 26 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 768 ms
6,940 KB
testcase_11 AC 679 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 9 ms
6,940 KB
testcase_14 AC 656 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 618 ms
6,940 KB
testcase_19 AC 9 ms
6,944 KB
testcase_20 AC 522 ms
6,944 KB
testcase_21 AC 795 ms
6,944 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 11 ms
6,944 KB
testcase_25 AC 5 ms
6,944 KB
testcase_26 AC 111 ms
6,940 KB
testcase_27 AC 159 ms
6,940 KB
testcase_28 AC 362 ms
6,940 KB
testcase_29 AC 125 ms
6,940 KB
testcase_30 AC 754 ms
6,940 KB
testcase_31 AC 4 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 4 ms
6,948 KB
testcase_34 AC 35 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;

const ll MOD = 1000000007;
ll N, K;
ll A[2020];
map<vector<ll>, ll> dp[2];

void solve() {
    cin >> N >> K;
    REP(i, N) cin >> A[i];

    if (K == 1) {
        ll ans = 1;
        REP(i, N) ans = ans * 2 % MOD;
        ans = (ans - 1 + MOD) % MOD;
        cout << ans << endl;
        return;
    }

    map<ll,ll> D;
    for (ll i = 2; i * i <= K; ++i) {
        while (K % i == 0) D[i] += 1, K /= i;
    }
    if (K > 1) D[K] += 1;

    vector<ll> keys;
    vector<ll> vals;
    for (const auto &item : D) {
        keys.push_back(item.first);
        vals.push_back(item.second);
    }

    vector<ll> y;
    REP(i, keys.size()) y.push_back(0);
    dp[0][y] = 1;

    int cur = 0, tar = 1;

    REP(i, N) {
        dp[tar].clear();
        for (auto hoge = begin(dp[cur]); hoge != end(dp[cur]); ++hoge) {
            dp[tar][hoge->first] = hoge->second;
        }

        vector<ll> x;
        for (const auto &item : D) {
            ll tmp = 0;
            while (A[i] % item.first == 0) tmp++, A[i] /= item.first;
            x.push_back(tmp);
        }
        for (auto hoge = begin(dp[cur]); hoge != end(dp[cur]); ++hoge) {
            REP(j, keys.size()) y[j] = min(x[j] + hoge->first[j], vals[j]);
            (dp[tar][y] += hoge->second) %= MOD;
        }

        swap(cur, tar);

    }

    cout << dp[cur][vals] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0