結果
問題 | No.1731 Product of Subsequence |
ユーザー |
|
提出日時 | 2021-11-05 23:26:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 881 ms / 2,000 ms |
コード長 | 1,575 bytes |
コンパイル時間 | 2,106 ms |
コンパイル使用メモリ | 186,816 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 04:52:55 |
合計ジャッジ時間 | 11,161 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,n) for (int i=0;i<(n);i++)#define REP2(i,m,n) for (int i=m;i<(n);i++)typedef long long ll;const ll MOD = 1000000007;ll N, K;ll A[2020];map<vector<ll>, ll> dp[2];void solve() {cin >> N >> K;REP(i, N) cin >> A[i];if (K == 1) {ll ans = 1;REP(i, N) ans = ans * 2 % MOD;ans = (ans - 1 + MOD) % MOD;cout << ans << endl;return;}map<ll,ll> D;for (ll i = 2; i * i <= K; ++i) {while (K % i == 0) D[i] += 1, K /= i;}if (K > 1) D[K] += 1;vector<ll> keys;vector<ll> vals;for (const auto &item : D) {keys.push_back(item.first);vals.push_back(item.second);}vector<ll> y;REP(i, keys.size()) y.push_back(0);dp[0][y] = 1;int cur = 0, tar = 1;REP(i, N) {dp[tar].clear();for (auto hoge = begin(dp[cur]); hoge != end(dp[cur]); ++hoge) {dp[tar][hoge->first] = hoge->second;}vector<ll> x;for (const auto &item : D) {ll tmp = 0;while (A[i] % item.first == 0) tmp++, A[i] /= item.first;x.push_back(tmp);}for (auto hoge = begin(dp[cur]); hoge != end(dp[cur]); ++hoge) {REP(j, keys.size()) y[j] = min(x[j] + hoge->first[j], vals[j]);(dp[tar][y] += hoge->second) %= MOD;}swap(cur, tar);}cout << dp[cur][vals] << endl;}int main() {cin.tie(0);ios::sync_with_stdio(false);solve();}