結果

問題 No.1731 Product of Subsequence
ユーザー norikamenorikame
提出日時 2021-11-13 13:41:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,381 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 209,268 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 17:50:54
合計ジャッジ時間 12,996 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 840 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 42 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 1,360 ms
6,940 KB
testcase_11 AC 1,190 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 15 ms
6,940 KB
testcase_14 AC 1,086 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 423 ms
6,940 KB
testcase_19 AC 12 ms
6,940 KB
testcase_20 AC 351 ms
6,944 KB
testcase_21 AC 1,381 ms
6,940 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 17 ms
6,944 KB
testcase_25 AC 7 ms
6,944 KB
testcase_26 AC 225 ms
6,940 KB
testcase_27 AC 305 ms
6,940 KB
testcase_28 AC 621 ms
6,940 KB
testcase_29 AC 232 ms
6,940 KB
testcase_30 AC 851 ms
6,944 KB
testcase_31 AC 5 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 5 ms
6,944 KB
testcase_34 AC 68 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

// 

const ll mod = (ll)(1e9) + 7;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	if (k == 1) {
		ll res = 1;
		rep(i, n) res = res * 2 % mod;
		res = (res - 1 + mod) % mod;
		cout << res << endl;
		return 0;
	}
	vector<pair<int, int>> kpvec;
	int ktmp = k;
	for (int i=2; i*i<=ktmp; ++i) if (ktmp%i == 0) {
		kpvec.emplace_back(i, 0);
		while (ktmp%i == 0) {
			kpvec.back().second++;
			ktmp /= i;
		}
	}
	if (ktmp > 1) kpvec.emplace_back(ktmp, 1);
	int m = kpvec.size();
	map<vector<pair<int, int>>, ll> dp;
	rep(i, n) {
		vector<pair<int, int>> aip;
		ll atmp = a[i];
		for (auto pi : kpvec) {
			aip.emplace_back(pi.first, 0);
			while (atmp%pi.first == 0) {
				aip.back().second++;
				atmp /= pi.first;
			}
			aip.back().second = min(aip.back().second, pi.second);
		}
		map<vector<pair<int, int>>, ll> ndp;
		ndp[aip] = (ndp[aip] + 1) % mod;
		for (auto pi : dp) {
			auto naip = pi.first;
			rep(j, m) naip[j].second = min(naip[j].second+aip[j].second, kpvec[j].second);
			ndp[naip] = (ndp[naip] + pi.second) % mod;
		}
		for (auto pi : ndp) dp[pi.first] = (dp[pi.first] + pi.second) % mod;
	}
	cout << dp[kpvec] << endl;
	return 0;
}
0