結果

問題 No.1731 Product of Subsequence
ユーザー tonyu0
提出日時 2021-11-06 00:04:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 611 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 119,224 KB
最終ジャッジ日時 2025-01-25 14:00:23
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)

constexpr int MOD = 1000000007;

unordered_map<ll, ll> dp[2002];
// dp[i][j] := i番目まで選んで、あまりj

int main() {
  cin.tie(0)->sync_with_stdio(0);
  ll n, k;
  cin >> n >> k;
  if(k==1){
      ll ii = 1;
      rep(i,0,n)(ii*=2)%=MOD;
      cout<<ii-1;
      return 0;
  }
  vector<ll> a(n);
  rep(i, 0, n){cin>>a[i];a[i]%=k;}
  dp[0][1] = 1;
  rep(i, 0, n) {
    for (auto &[j, v] : dp[i]) {
      (dp[i + 1][gcd(j * a[i], k)] += v)%=MOD;
      (dp[i + 1][j] += v)%=MOD;
    }
  }
  cout << dp[n][k];

  return 0;
}
0