結果
| 問題 | No.1731 Product of Subsequence |
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-05-26 21:11:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,056 bytes |
| 記録 | |
| コンパイル時間 | 3,924 ms |
| コンパイル使用メモリ | 263,552 KB |
| 最終ジャッジ日時 | 2025-02-13 05:24:12 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 TLE * 16 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef modint1000000007 mint;
typedef long long ll;
vector<pair<int,int>> pfact(int n){
vector<pair<int,int>> ret;
for (int i=2; i*i<=n; i++){
if (n%i == 0){
int cnt = 0;
while (n%i == 0){
n /= i;
cnt++;
}
ret.push_back(pair(i, cnt));
}
}
if (n > 1) ret.push_back(pair(n, 1));
return ret;
}
int main(){
int n, k; cin >> n >> k;
vector<pair<int,int>> pf = pfact(k);
vector<int> pl;
for (auto [p,c]: pf){
pl.push_back(p);
}
vector<ll> a(n);
for (int i=0; i<n; i++){
cin >> a[i];
ll nw = 1;
for (int j: pl){
while (a[i] % j == 0){
nw *= j;
a[i] /= j;
}
}
a[i] = nw;
}
map<int,mint> s;
s[1] = 1;
for (int i=0; i<n; i++){
map<int,mint> ns = s;
for (auto j=s.begin(); j!=s.end(); j++){
int tmp = (ll)j->first * a[i] % k;
if (ns.find(tmp) == ns.end()){
ns[tmp] = 0;
}
ns[tmp] += j->second;
}
s = ns;
}
if (s.find(0) == s.end()){
s[0] = 0;
}
cout << s[0].val() << endl;
}
shobonvip