結果
| 問題 | No.1731 Product of Subsequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-05 22:33:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 926 bytes |
| 記録 | |
| コンパイル時間 | 2,035 ms |
| コンパイル使用メモリ | 180,080 KB |
| 実行使用メモリ | 169,216 KB |
| 最終ジャッジ日時 | 2024-11-06 13:32:55 |
| 合計ジャッジ時間 | 17,410 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 WA * 4 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
int N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, 0, N) cin >> A[i];
vector<map<ll, ll>> dp(N + 1);
dp[0][1] = 1;
ll MOD = 1000000007;
rep(i, 0, N) {
for (auto j : dp[i]) {
dp[i + 1][j.first] = (dp[i + 1][j.first] + j.second) % MOD;
ll x = gcd(j.first * gcd(A[i], K), K);
dp[i + 1][x] = (dp[i + 1][x] + j.second) % MOD;
}
}
ll ans = 0;
for (auto i : dp[N]) {
if (i.first % K == 0) ans = (ans + i.second) % MOD;
}
cout << ans << endl;
/*
rep(i, 0, N + 1) {
for (auto j : dp[i]) {
cout << "(" << j.first << "," << j.second << ")";
}
cout << endl;
}
*/
}