結果

問題 No.2313 Product of Subsequence (hard)
ユーザー 👑 hitonanodehitonanode
提出日時 2023-05-24 22:11:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,167 ms / 4,000 ms
コード長 1,773 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 128,972 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-25 14:03:55
合計ジャッジ時間 14,092 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 112 ms
4,380 KB
testcase_09 AC 36 ms
4,380 KB
testcase_10 AC 99 ms
4,380 KB
testcase_11 AC 30 ms
4,376 KB
testcase_12 AC 98 ms
4,380 KB
testcase_13 AC 1,152 ms
4,376 KB
testcase_14 AC 1,143 ms
4,380 KB
testcase_15 AC 1,157 ms
4,376 KB
testcase_16 AC 1,167 ms
4,380 KB
testcase_17 AC 1,120 ms
4,380 KB
testcase_18 AC 1,128 ms
4,380 KB
testcase_19 AC 1,152 ms
4,376 KB
testcase_20 AC 1,123 ms
4,504 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 48 ms
4,380 KB
testcase_26 AC 31 ms
4,380 KB
testcase_27 AC 1,128 ms
4,380 KB
testcase_28 AC 167 ms
4,380 KB
testcase_29 AC 60 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
#include <atcoder/modint>
using namespace std;

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    int K;
    cin >> N >> K;

    vector<pair<int, int>> fac;
    int len = 1;
    for (int p = 2; p * p <= K; ++p) {
        if (K % p) continue;
        fac.emplace_back(p, 0);
        while (K % p == 0) {
            K /= p;
            ++fac.back().second;
        }
        len *= 1 + fac.back().second;
    }
    if (K > 1) fac.emplace_back(K, 1), len *= 2;

    vector<atcoder::modint998244353> dp(len);
    dp.front() = 1;

    map<vector<int>, int> mp;
    while (N--) {
        long long a;
        cin >> a;
        vector<int> ds;
        for (auto [p, deg] : fac) {
            int m = 0;
            while (a % p == 0) a /= p, ++m;
            ds.push_back(min(m, deg));
        }
        mp[ds]++;
    }

    for (auto [ds, cnt] : mp) {
        vector<int> to(dp.size(), -1);
        auto rec = [&](auto &&self, int d, int prv, int nxt) -> void {
            if (d == int(fac.size())) {
                to.at(prv) = nxt;
            } else {
                int m = fac.at(d).second;
                REP(h, m + 1) {
                    self(self, d + 1, prv * (m + 1) + h, nxt * (m + 1) + min(m, ds.at(d) + h));
                }
            }
        };
        rec(rec, 0, 0, 0);
        while (cnt--) IREP(i, dp.size()) dp.at(to.at(i)) += dp.at(i);
    }

    dp.front() -= 1;

    cout << dp.back().val() << endl;
}
0