結果

問題 No.1731 Product of Subsequence
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-01-16 15:06:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,036 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 120,512 KB
実行使用メモリ 169,092 KB
最終ジャッジ日時 2023-08-29 22:11:17
合計ジャッジ時間 13,339 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 902 ms
157,516 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 31 ms
8,216 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 1,034 ms
168,448 KB
testcase_11 AC 887 ms
145,640 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 14 ms
7,144 KB
testcase_14 AC 781 ms
128,280 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 800 ms
133,536 KB
testcase_19 AC 15 ms
7,364 KB
testcase_20 AC 645 ms
109,344 KB
testcase_21 AC 1,036 ms
169,092 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 13 ms
7,092 KB
testcase_25 AC 6 ms
4,824 KB
testcase_26 AC 157 ms
32,140 KB
testcase_27 AC 214 ms
41,508 KB
testcase_28 AC 459 ms
79,200 KB
testcase_29 AC 170 ms
34,052 KB
testcase_30 AC 905 ms
167,760 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 58 ms
15,800 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