結果

問題 No.1731 Product of Subsequence
ユーザー bonKotsubonKotsu
提出日時 2022-07-23 17:15:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,291 bytes
コンパイル時間 4,769 ms
コンパイル使用メモリ 266,592 KB
実行使用メモリ 22,064 KB
最終ジャッジ日時 2023-09-18 16:15:54
合計ジャッジ時間 12,568 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };

using mint = modint1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<int> kdiv;
  for (int i = 1; i*i <= k; i++) {
    if (k%i==0) {
      if (i*i==k) kdiv.pb(i);
      else {
        kdiv.pb(i);
        kdiv.pb(k/i);
      }
    }
  }
  vector<ll> g(n);
  rep(i,n) {
    g[i] = gcd(a[i],k);
  }

  sort(all(kdiv));
  int m = kdiv.size();
  vector dp(n+1, vector<mint>(m));
  dp[0][0] = 1;
  rep(i,n) {
    rep(j,m) {
      dp[i+1][j] += dp[i][j];
      for (int l = m-1; l >= j; l--) {
        if (l == j) {
          dp[i+1][l] += dp[i][j];
          break;
        }
        if ((g[i]*kdiv[j])%kdiv[l] == 0) {
          dp[i+1][l] += dp[i][j];
          break;
        }
      }
    }
  }

  cout << dp[n][m-1].val() << endl;




  
  return 0;
}
0