結果
問題 | No.917 Make One With GCD |
ユーザー |
|
提出日時 | 2019-09-13 14:24:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 613 bytes |
コンパイル時間 | 819 ms |
コンパイル使用メモリ | 86,596 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:02:56 |
合計ジャッジ時間 | 1,854 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> #include <vector> #include <unordered_map> using namespace std; using ll = long long; template<typename T> T gcd_(T a, T b) { while (b) { T tmp = b; b = a % b; a = tmp; } return a; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; unordered_map<int, ll> dp; for (int x : a) { unordered_map<int, ll> new_dp = dp; for (auto& p : dp) { new_dp[gcd_(p.first, x)] += p.second; } new_dp[x]++; dp = move(new_dp); } cout << dp[1] << endl; return 0; }