結果

問題 No.1731 Product of Subsequence
ユーザー nebukuro09nebukuro09
提出日時 2021-11-05 23:13:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,499 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 181,888 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 07:14:20
合計ジャッジ時間 11,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 878 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 30 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 880 ms
5,376 KB
testcase_11 AC 755 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 761 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 704 ms
5,376 KB
testcase_19 AC 10 ms
5,376 KB
testcase_20 AC 575 ms
5,376 KB
testcase_21 AC 883 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 11 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 124 ms
5,376 KB
testcase_27 AC 180 ms
5,376 KB
testcase_28 AC 420 ms
5,376 KB
testcase_29 AC 133 ms
5,376 KB
testcase_30 AC 877 ms
5,376 KB
testcase_31 AC 5 ms
5,376 KB
testcase_32 WA -
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 36 ms
5,376 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 print(vector<ll> v) {
    REP(i, v.size()) cout << v[i] << " ";
    cout << endl;
}

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

    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