結果

問題 No.1731 Product of Subsequence
ユーザー nawawannawawan
提出日時 2021-11-05 22:20:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 819 ms / 2,000 ms
コード長 2,990 bytes
コンパイル時間 2,491 ms
コンパイル使用メモリ 210,664 KB
実行使用メモリ 13,244 KB
最終ジャッジ日時 2023-08-07 23:13:37
合計ジャッジ時間 10,968 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 656 ms
13,020 KB
testcase_01 AC 6 ms
12,844 KB
testcase_02 AC 6 ms
12,852 KB
testcase_03 AC 6 ms
12,924 KB
testcase_04 AC 6 ms
12,880 KB
testcase_05 AC 6 ms
12,856 KB
testcase_06 AC 6 ms
12,976 KB
testcase_07 AC 6 ms
12,860 KB
testcase_08 AC 27 ms
13,244 KB
testcase_09 AC 8 ms
13,120 KB
testcase_10 AC 812 ms
13,032 KB
testcase_11 AC 696 ms
13,008 KB
testcase_12 AC 7 ms
13,008 KB
testcase_13 AC 18 ms
12,868 KB
testcase_14 AC 627 ms
13,132 KB
testcase_15 AC 6 ms
12,992 KB
testcase_16 AC 6 ms
13,068 KB
testcase_17 AC 6 ms
12,928 KB
testcase_18 AC 576 ms
13,020 KB
testcase_19 AC 18 ms
12,944 KB
testcase_20 AC 474 ms
13,144 KB
testcase_21 AC 819 ms
13,136 KB
testcase_22 AC 8 ms
12,860 KB
testcase_23 AC 7 ms
12,916 KB
testcase_24 AC 18 ms
12,988 KB
testcase_25 AC 10 ms
12,988 KB
testcase_26 AC 132 ms
12,924 KB
testcase_27 AC 178 ms
13,124 KB
testcase_28 AC 369 ms
12,968 KB
testcase_29 AC 145 ms
12,956 KB
testcase_30 AC 670 ms
13,220 KB
testcase_31 AC 7 ms
12,996 KB
testcase_32 AC 6 ms
13,164 KB
testcase_33 AC 8 ms
12,972 KB
testcase_34 AC 54 ms
13,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<const int MOD> struct modint{
    long long val;
    modint(): val(0) {}
    modint(long long x){
        if(x < 0) val = x % MOD + MOD;
        else val = x % MOD;
    }
    modint(const modint &t){
        val = t.val;
    }
    modint& operator =(const modint m){
        val = m.val;
        return *this;
    }
    modint operator -(){
        return modint(-val);
    }
    modint& operator-=(const modint &m){
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    modint& operator+=(const modint &m){
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    modint& operator*=(const modint &m){
        val *= m.val;
        val %= MOD;
        return *this;
    }
    modint& operator/=(modint m){
        *this *= m.inv();
        return *this;
    }
    modint inv(){
        long long x = 1, y = 0;
        long long a = val, b = MOD;
        while(b != 0){
            long long t = a / b;
            a -= t * b;
            x -= t * y;
            swap(a, b);
            swap(x, y);
        }
        x %= MOD;
        if(x < 0) x += MOD;
        return modint(x);
    }
    modint pow(long long k){
        long long res = 1;
        long long v = val;
        while(k > 0){
            if(k & 1) res = res * v % MOD;
            v = v * v % MOD;
            k >>= 1;
    }
        return modint(res);
    }
    bool operator==(const modint &m){
        return val == m.val;
    }
    modint operator+(const modint &m){
        return modint(*this) += m;
    }
    modint operator-(const modint &m){
        return modint(*this) -= m;
    }
    modint operator*(const modint &m){
        return modint(*this) *= m;
    }
    modint operator/(const modint &m){
        return modint(*this) /= m;
    }
    bool operator!=(const modint &m){
        return modint(*this).val != m.val;
    }
    bool operator!=(const int &m){
        return modint(*this).val != m;
    }
};
const int MOD = 1000000007;
using mint = modint<MOD>;
const int MAX = 410000;
mint fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
        inv[i] = mint(MOD) - inv[MOD % i] * (MOD / i);
        finv[i] = finv[i - 1] * inv[i];
    }
}
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    map<long long, mint> dp;
    dp[1] += 1;
    for(int i = 0; i < N; i++){
        map<long long, mint> m2;
        for(auto [now, cnt] : dp){
            long long rest = K / now;
            long long g = gcd(rest, A[i]);
            m2[now] += cnt;
            m2[now * g] += cnt;
        }
        dp.swap(m2);
    }
    dp[1] -= 1;
    cout << dp[K].val << endl;
}
0