結果

問題 No.1731 Product of Subsequence
ユーザー ぷらぷら
提出日時 2021-11-05 21:28:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 975 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 200,388 KB
実行使用メモリ 32,640 KB
最終ジャッジ日時 2024-04-24 05:15:46
合計ジャッジ時間 8,388 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 362 ms
31,616 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 24 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 496 ms
32,640 KB
testcase_11 AC 424 ms
29,440 KB
testcase_12 AC 13 ms
11,648 KB
testcase_13 AC 17 ms
11,904 KB
testcase_14 AC 387 ms
27,520 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 342 ms
32,512 KB
testcase_19 AC 18 ms
11,904 KB
testcase_20 AC 289 ms
28,416 KB
testcase_21 AC 497 ms
32,512 KB
testcase_22 AC 227 ms
32,640 KB
testcase_23 WA -
testcase_24 AC 20 ms
12,032 KB
testcase_25 AC 15 ms
11,648 KB
testcase_26 AC 90 ms
15,360 KB
testcase_27 AC 120 ms
16,512 KB
testcase_28 AC 240 ms
21,504 KB
testcase_29 AC 104 ms
15,616 KB
testcase_30 AC 377 ms
32,640 KB
testcase_31 AC 210 ms
32,512 KB
testcase_32 WA -
testcase_33 AC 24 ms
13,056 KB
testcase_34 AC 40 ms
13,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a,long long b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return gcd(b,a % b);
    }
}

long long dp[2005][5005];
constexpr int mod = 1000000007;

int main() {
    int N,K;
    cin >> N >> K;
    vector<int>tmp;
    for(int i = 1; i*i <= K; i++) {
        if(K%i == 0) {
            tmp.push_back(i);
            if(i*i != K) {
                tmp.push_back(K/i);
            }
        }
    }
    sort(tmp.begin(),tmp.end());
    dp[0][tmp.size()-1] = 1;
    for(int i = 0; i < N; i++) {
        long long A;
        cin >> A;
        for(int j = 0; j < tmp.size(); j++) {
            long long nxt = tmp[j]/gcd(A,tmp[j]);
            int it = lower_bound(tmp.begin(),tmp.end(),nxt)-tmp.begin();
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= mod;
            dp[i+1][it] += dp[i][j];
            dp[i+1][it] %= mod;
        }
    }
    cout << dp[N][0] << endl;
}
0