結果
問題 | No.917 Make One With GCD |
ユーザー |
|
提出日時 | 2022-12-10 18:52:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 544 bytes |
コンパイル時間 | 1,823 ms |
コンパイル使用メモリ | 176,148 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 23:50:11 |
合計ジャッジ時間 | 2,870 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); vector<map<int,ll>> dp(n + 1); for(auto &&v:a)cin >> v; dp[0][0] = 1; ll ans = 0; for(int i = 0; i <= n; i++){ for(auto &&p:dp[i]){ if(p.first == 1)ans += p.second; for(int j = i + 1; j <= n; j++){ dp[j][__gcd(a[j - 1], p.first)] += p.second; } } } cout << ans << '\n'; }