結果

問題 No.1731 Product of Subsequence
ユーザー V_MelvilleV_Melville
提出日時 2021-11-10 22:01:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 725 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 6,891 ms
コンパイル使用メモリ 338,112 KB
実行使用メモリ 127,872 KB
最終ジャッジ日時 2024-04-25 17:49:38
合計ジャッジ時間 13,149 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 633 ms
119,424 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 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,940 KB
testcase_08 AC 21 ms
7,296 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 725 ms
127,616 KB
testcase_11 AC 623 ms
110,208 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 550 ms
97,408 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 567 ms
101,120 KB
testcase_19 AC 13 ms
6,944 KB
testcase_20 AC 456 ms
82,944 KB
testcase_21 AC 720 ms
127,872 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 12 ms
6,944 KB
testcase_25 AC 6 ms
6,944 KB
testcase_26 AC 113 ms
25,088 KB
testcase_27 AC 158 ms
32,512 KB
testcase_28 AC 322 ms
60,416 KB
testcase_29 AC 125 ms
26,624 KB
testcase_30 AC 636 ms
126,976 KB
testcase_31 AC 4 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 4 ms
6,940 KB
testcase_34 AC 43 ms
12,800 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::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<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