結果

問題 No.1731 Product of Subsequence
ユーザー yasuwoyasuwo
提出日時 2021-11-27 17:54:58
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,534 bytes
コンパイル時間 6,187 ms
コンパイル使用メモリ 319,440 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 21:15:08
合計ジャッジ時間 10,994 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 251 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 20 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 366 ms
4,380 KB
testcase_11 AC 308 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 286 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 245 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 203 ms
4,376 KB
testcase_21 AC 372 ms
4,380 KB
testcase_22 AC 69 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 60 ms
4,376 KB
testcase_27 AC 81 ms
4,380 KB
testcase_28 AC 169 ms
4,376 KB
testcase_29 AC 67 ms
4,380 KB
testcase_30 AC 216 ms
4,380 KB
testcase_31 AC 70 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 6 ms
4,376 KB
testcase_34 AC 23 ms
4,376 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);
    }
    vector<mint> dp(vK.size());
    dp[0] = 1;
    for (int i = 0; i < N; i++)
    {
        vector<mint> nxtdp = dp;
        // ll g = gcd(K, A[i]);
        for (int x = 0; x < vK.size(); x++)
        {
            ll k = vK[x];
            k *= A[i];
            k = gcd(k, K);
            int y = mpK[k];
            nxtdp[y] += dp[x];
        }
        swap(dp, nxtdp);
    }
    return dp[mpK[K]].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;
    }
    auto ans = solve(N, K, A);
    std::cout << ans << '\n';
    return 0;
}
0