結果

問題 No.1731 Product of Subsequence
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-16 15:07:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,024 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 120,008 KB
実行使用メモリ 168,992 KB
最終ジャッジ日時 2023-08-29 22:12:02
合計ジャッジ時間 12,005 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 904 ms
157,568 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 30 ms
8,192 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1,020 ms
168,356 KB
testcase_11 AC 877 ms
145,624 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 13 ms
7,272 KB
testcase_14 AC 771 ms
128,208 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 790 ms
133,492 KB
testcase_19 AC 16 ms
7,136 KB
testcase_20 AC 643 ms
109,320 KB
testcase_21 AC 1,024 ms
168,992 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 13 ms
7,068 KB
testcase_25 AC 6 ms
4,972 KB
testcase_26 AC 154 ms
32,236 KB
testcase_27 AC 212 ms
41,480 KB
testcase_28 AC 457 ms
79,200 KB
testcase_29 AC 166 ms
34,196 KB
testcase_30 AC 893 ms
167,776 KB
testcase_31 AC 4 ms
4,384 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 56 ms
15,924 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;

const long long modc = 1e9+7;

int main(){

    long long N, K, X, g;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i=0; i<N; i++) cin >> A[i];

    vector<map<long long, long long>> dp(N+1);
    dp[0][1] = 1;

    for (int i=1; i<=N; i++){
        X = gcd(K, A[i-1]);
        for (auto &[a, b] : dp[i-1]){
            dp[i][a] += b;
            dp[i][a] %= modc;

            g = gcd(X*a, K);
            dp[i][g] += b;
            dp[i][g] %= modc;
        }
    }

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

    return 0;
}
0