結果
問題 | No.1731 Product of Subsequence |
ユーザー | 👑 platinum |
提出日時 | 2021-11-05 22:01:03 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,005 ms / 2,000 ms |
コード長 | 1,691 bytes |
コンパイル時間 | 2,151 ms |
コンパイル使用メモリ | 211,132 KB |
実行使用メモリ | 169,072 KB |
最終ジャッジ日時 | 2023-08-07 23:07:25 |
合計ジャッジ時間 | 11,966 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 829 ms
157,488 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 26 ms
8,288 KB |
testcase_09 | AC | 3 ms
4,376 KB |
testcase_10 | AC | 1,005 ms
168,560 KB |
testcase_11 | AC | 859 ms
145,660 KB |
testcase_12 | AC | 3 ms
4,380 KB |
testcase_13 | AC | 18 ms
7,160 KB |
testcase_14 | AC | 758 ms
128,288 KB |
testcase_15 | AC | 2 ms
4,380 KB |
testcase_16 | AC | 1 ms
4,376 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 715 ms
133,644 KB |
testcase_19 | AC | 18 ms
7,208 KB |
testcase_20 | AC | 578 ms
109,308 KB |
testcase_21 | AC | 990 ms
169,072 KB |
testcase_22 | AC | 4 ms
4,380 KB |
testcase_23 | AC | 3 ms
4,376 KB |
testcase_24 | AC | 20 ms
7,032 KB |
testcase_25 | AC | 8 ms
4,920 KB |
testcase_26 | AC | 159 ms
32,172 KB |
testcase_27 | AC | 219 ms
41,512 KB |
testcase_28 | AC | 447 ms
79,240 KB |
testcase_29 | AC | 178 ms
34,140 KB |
testcase_30 | AC | 873 ms
167,820 KB |
testcase_31 | AC | 3 ms
4,380 KB |
testcase_32 | AC | 2 ms
4,380 KB |
testcase_33 | AC | 4 ms
4,380 KB |
testcase_34 | AC | 64 ms
15,884 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair<int,int>; using vv = vector<vector<int>>; const int INF = (int)1e9; const LL LINF = (LL)1e18; long long const mod = 1000000007; struct mint{ long long val; mint(long long val = 0): val(val % mod) {} mint& operator += (const mint n){ val += n.val; if(val >= mod) val -= mod; return *this; } mint& operator -= (const mint n){ val -= n.val; if(val < 0) val += mod; return *this; } mint& operator *= (const mint n){ val *= n.val; val %= mod; if(val < 0) val += mod; return *this; } mint operator + (const mint n) const{ mint res(*this); return res += n; } mint operator - (const mint n) const{ mint res(*this); return res -= n; } mint operator * (const mint n) const{ mint res(*this); return res *= n; } mint pow(long long n) const{ if(n == 0) return 1; mint m = pow(n >> 1); m *= m; if(n & 1) m *= *this; return m; } // mint division for prime mod mint inv() const{ return pow(mod - 2); } mint& operator /= (const mint n){ return (*this) *= n.inv(); } mint operator / (const mint n) const{ mint res(*this); return res /= n; } }; int main(){ int N; LL K; cin >> N >> K; vector<LL> A(N); rep(i,N) cin >> A[i]; if(K == 1){ mint base = 2; mint ans = base.pow(N); ans -= 1; cout << ans.val << endl; return 0; } vector<map<LL,mint>> dp(N+1); dp[0][K] = 1; rep(i,N){ for(auto itr : dp[i]){ LL res = itr.first; mint cnt = itr.second; dp[i+1][res] += cnt; LL g = gcd(res, A[i]); dp[i+1][res / g] += cnt; } } cout << dp[N][1].val << endl; return 0; }