結果

問題 No.1731 Product of Subsequence
ユーザー V_MelvilleV_Melville
提出日時 2021-11-06 21:28:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 6,405 ms
コンパイル使用メモリ 337,168 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-04-25 17:42:15
合計ジャッジ時間 8,551 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
13,440 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 8 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 128 ms
14,080 KB
testcase_11 AC 112 ms
12,416 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 113 ms
11,520 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 132 ms
14,080 KB
testcase_19 AC 5 ms
6,944 KB
testcase_20 AC 109 ms
11,904 KB
testcase_21 AC 130 ms
14,208 KB
testcase_22 AC 99 ms
13,952 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 6 ms
6,940 KB
testcase_25 AC 5 ms
6,944 KB
testcase_26 AC 24 ms
6,940 KB
testcase_27 AC 31 ms
6,940 KB
testcase_28 AC 65 ms
8,960 KB
testcase_29 AC 27 ms
6,940 KB
testcase_30 AC 116 ms
13,824 KB
testcase_31 AC 98 ms
14,080 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 9 ms
6,948 KB
testcase_34 AC 11 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::gcd;
using std::unordered_map;
using std::vector;
using ll = long long;
using mint = modint1000000007;

int main() {
	int n, k;
	cin >> n >> k;
	
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) a[i] = gcd(a[i], k);
	
	vector<ll> f;
	for(ll i = 1; i*i <= k; ++i) {
		if (k % i == 0) {
			f.push_back(i);
			if (k/i != i) f.push_back(k/i);
		}
	}
	sort(f.begin(), f.end());
	int m = f.size();
	unordered_map<ll, int> mp;
	rep(i, m) mp[f[i]] = i;
	
	vector dp(n+1, vector<mint>(m));
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, m) {
			dp[i+1][j] += dp[i][j];
			
			ll g = gcd(f[j]*a[i], k);
			dp[i+1][mp[g]] += dp[i][j];
		}
	}
	
	mint ans = dp[n][m-1];
	if (k == 1) ans -= 1;
	cout << ans.val() << '\n';
	
	return 0;
}
0