結果
問題 | No.1731 Product of Subsequence |
ユーザー |
![]() |
提出日時 | 2024-11-21 09:29:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,024 bytes |
コンパイル時間 | 4,395 ms |
コンパイル使用メモリ | 232,348 KB |
実行使用メモリ | 13,640 KB |
最終ジャッジ日時 | 2024-11-21 09:30:49 |
合計ジャッジ時間 | 61,851 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 TLE * 1 |
other | AC * 5 WA * 9 TLE * 17 |
ソースコード
#include <bits/extc++.h> using i64 = long long; constexpr int P = 1E9 + 7; inline void Inc(int &x, int y) { if ((x += y) >= P) x -= P; } int main() { std::cin.tie(nullptr) -> sync_with_stdio(false); int n, m; std::cin >> n >> m; std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; a[i] = std::__gcd(a[i], m); } auto lcm = [&](int x, int y) { return 1ll * x * y / std::__gcd(x, y); }; int cnt = 0; __gnu_pbds::gp_hash_table<int, int> mp; std::vector<int> d; for (int i = 1; i <= m; i++) { if (m % i == 0) { mp[i] = cnt++; d.push_back(i); } } std::vector<int> f(cnt); f[0] = 1; for (int i = 0; i < n; i++) { std::vector<int> nf(cnt); for (auto x : d) { Inc(nf[mp[std::__gcd(1ll * m, 1ll * x * a[i])]], f[mp[x]]); Inc(nf[mp[x]], f[mp[x]]); } f = nf; } std::cout << f[cnt - 1]; return 0; }