結果

問題 No.1731 Product of Subsequence
ユーザー umezoumezo
提出日時 2021-11-07 19:47:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,377 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 220,096 KB
実行使用メモリ 32,620 KB
最終ジャッジ日時 2023-08-07 23:36:43
合計ジャッジ時間 18,839 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,207 ms
31,720 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 66 ms
5,040 KB
testcase_09 AC 11 ms
11,336 KB
testcase_10 AC 1,370 ms
32,548 KB
testcase_11 AC 1,161 ms
29,564 KB
testcase_12 AC 11 ms
11,436 KB
testcase_13 AC 23 ms
11,776 KB
testcase_14 AC 1,025 ms
27,388 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1,280 ms
32,620 KB
testcase_19 AC 22 ms
12,032 KB
testcase_20 AC 1,034 ms
28,360 KB
testcase_21 AC 1,377 ms
32,576 KB
testcase_22 AC 1,092 ms
32,476 KB
testcase_23 AC 10 ms
11,448 KB
testcase_24 AC 23 ms
11,892 KB
testcase_25 AC 16 ms
11,580 KB
testcase_26 AC 209 ms
15,256 KB
testcase_27 AC 293 ms
16,400 KB
testcase_28 AC 621 ms
21,380 KB
testcase_29 AC 225 ms
15,564 KB
testcase_30 AC 1,229 ms
32,548 KB
testcase_31 AC 1,057 ms
32,520 KB
testcase_32 AC 10 ms
11,384 KB
testcase_33 AC 32 ms
13,148 KB
testcase_34 AC 74 ms
12,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

ll dp[2010][2010];
const int MOD=1e9+7;

vector<ll> divisor(ll x){
  set<ll> s;
  for(ll i=1;i*i<=x;i++){
    if(x%i==0){
      s.insert(i);
      s.insert(x/i);
    }
  }
  vector<ll> res;
  for(auto y:s) res.push_back(y);
  sort(ALL(res));
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,k;
  cin>>n>>k;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  
  vector<ll> D=divisor(k);
  int d=D.size();
  map<ll,ll> m;
  rep(i,d) m[D[i]]=i;
  
  dp[0][0]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<d;j++){
      ll tmp=D[j];
      dp[i][m[tmp]]=(dp[i][m[tmp]]+dp[i-1][m[tmp]])%MOD;
      ll b=gcd(A[i-1],k);
      ll c=k/b;
      ll a=gcd(c,tmp);
      dp[i][m[a*b]]=(dp[i][m[a*b]]+dp[i-1][m[tmp]])%MOD;
    }
  }
  if(k==1) cout<<dp[n][m[k]]-1<<endl;
  else cout<<dp[n][m[k]]<<endl;

  return 0;
}
0