結果

問題 No.1731 Product of Subsequence
ユーザー V_MelvilleV_Melville
提出日時 2021-11-10 22:12:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 611 ms / 2,000 ms
コード長 726 bytes
コンパイル時間 6,284 ms
コンパイル使用メモリ 337,056 KB
実行使用メモリ 122,880 KB
最終ジャッジ日時 2024-04-25 17:49:51
合計ジャッジ時間 12,962 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 565 ms
116,096 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 16 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 611 ms
122,880 KB
testcase_11 AC 533 ms
110,976 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 14 ms
6,944 KB
testcase_14 AC 438 ms
83,200 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 463 ms
96,128 KB
testcase_19 AC 14 ms
6,940 KB
testcase_20 AC 370 ms
73,088 KB
testcase_21 AC 607 ms
122,880 KB
testcase_22 AC 5 ms
6,944 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 15 ms
6,940 KB
testcase_25 AC 6 ms
6,940 KB
testcase_26 AC 98 ms
22,144 KB
testcase_27 AC 146 ms
30,848 KB
testcase_28 AC 287 ms
58,496 KB
testcase_29 AC 117 ms
23,040 KB
testcase_30 AC 577 ms
121,984 KB
testcase_31 AC 4 ms
6,944 KB
testcase_32 AC 3 ms
6,944 KB
testcase_33 AC 4 ms
6,940 KB
testcase_34 AC 46 ms
11,904 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<unordered_map<int, mint>> dp(n+1);
	dp[0][1] = 1;
	rep(i, n) {
		for (auto [j, x] : dp[i]) {
			// 不取 a[i] 
			dp[i+1][j] += x;
			// 取 a[i] 
			ll g = gcd(j*a[i], k);
			dp[i+1][g] += x;
		}
	}
	
	mint ans = dp[n][k];
	if (k == 1) ans -= 1;
	cout << ans.val() << '\n';
	
	return 0;
}
0