結果

問題 No.1731 Product of Subsequence
ユーザー yasuwoyasuwo
提出日時 2021-11-27 18:17:27
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 1,642 bytes
コンパイル時間 5,829 ms
コンパイル使用メモリ 337,936 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 17:53:42
合計ジャッジ時間 9,674 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 226 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 19 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 350 ms
6,940 KB
testcase_11 AC 295 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 285 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 235 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 199 ms
6,944 KB
testcase_21 AC 359 ms
6,940 KB
testcase_22 AC 67 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 10 ms
6,940 KB
testcase_25 AC 5 ms
6,940 KB
testcase_26 AC 59 ms
6,940 KB
testcase_27 AC 78 ms
6,944 KB
testcase_28 AC 163 ms
6,940 KB
testcase_29 AC 71 ms
6,940 KB
testcase_30 AC 212 ms
6,940 KB
testcase_31 AC 83 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 5 ms
6,944 KB
testcase_34 AC 21 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
#include <atcoder/all>
// #include "library/templates/template.hpp"
using namespace atcoder;
using namespace std;
using ll = long long int;

vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}
using mint = modint1000000007;

long long solve(int N, long long K, const std::vector<long long> &A)
{
    auto divK = divisor(K);
    // cerr << divK << endl;
    map<ll, ll> mpK;
    vector<ll> vK;
    for (ll x : divK)
    {
        mpK[x] = vK.size();
        vK.push_back(x);
    }
    mpK[0] = mpK[K];
    vector<mint> dp(vK.size());
    dp[mpK[1]] = 1;
    for (int i = 0; i < N; i++)
    {
        vector<mint> nxtdp = dp;
        for (size_t x = 0; x < vK.size(); x++)
        {
            ll k = vK[x];
            k *= A[i];
            ll g = gcd(k, K);
            int y = mpK[g];
            nxtdp[y] += dp[x];
        }
        swap(dp, nxtdp);
    }
    mint ans = dp[mpK[0]];
    if (ans == mint(2).pow(N))
    {
        ans--;
    }
    return ans.val();
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int N;
    long long K;
    std::cin >> N >> K;
    std::vector<long long> A(N);
    for (int i = 0; i < N; ++i)
    {
        std::cin >> A[i];
        A[i] %= K;
    }
    sort(A.begin(), A.end());
    auto ans = solve(N, K, A);
    std::cout << ans << '\n';
    return 0;
}
0