結果
問題 |
No.1731 Product of Subsequence
|
ユーザー |
|
提出日時 | 2021-11-10 22:01:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 770 ms / 2,000 ms |
コード長 | 706 bytes |
コンパイル時間 | 5,798 ms |
コンパイル使用メモリ | 316,928 KB |
実行使用メモリ | 127,744 KB |
最終ジャッジ日時 | 2024-11-08 05:10:03 |
合計ジャッジ時間 | 13,861 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#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; }