結果

問題 No.1731 Product of Subsequence
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-03 01:14:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,012 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 125,140 KB
実行使用メモリ 169,048 KB
最終ジャッジ日時 2023-08-28 07:16:33
合計ジャッジ時間 12,605 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 890 ms
157,560 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 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,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 29 ms
8,208 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 1,012 ms
168,368 KB
testcase_11 AC 866 ms
145,608 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 12 ms
7,172 KB
testcase_14 AC 749 ms
128,268 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 773 ms
133,508 KB
testcase_19 AC 15 ms
7,260 KB
testcase_20 AC 627 ms
109,576 KB
testcase_21 AC 1,012 ms
169,048 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 13 ms
7,024 KB
testcase_25 AC 6 ms
4,828 KB
testcase_26 AC 152 ms
32,196 KB
testcase_27 AC 206 ms
41,488 KB
testcase_28 AC 442 ms
79,168 KB
testcase_29 AC 163 ms
34,040 KB
testcase_30 AC 885 ms
167,788 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 55 ms
15,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

vector<ll> factor;

void all_factor(ll n){
    for (ll i = 1; i*i <= n; i++){
        if (n % i == 0){
            factor.push_back(i);
            if (i*i != n) factor.push_back(n / i);
        }
    }
    sort(factor.begin(), factor.end());
}

const ll modc = 1e9+7;

int main(){

    ll N, K, g;
    cin >> N >> K;
    all_factor(K);
    vector<ll> A(N+1);
    vector<map<ll, ll>> dp(N+1);
    for (int i=1; i<=N; i++){
        cin >> A[i];
        A[i] = gcd(A[i], K);
    }
    dp[0][1] = 1;
    for (int i=1; i<=N; i++){
        for (auto [x, y] : dp[i-1]){
            dp[i][x] += y;
            dp[i][x] %= modc;
            g = gcd(A[i]*x, K);
            dp[i][g] += y;
            dp[i][g] %= modc;
        }
    }

    cout << dp[N][K] - (K == 1) << endl;

    return 0;
}
0