結果
問題 |
No.917 Make One With GCD
|
ユーザー |
|
提出日時 | 2019-12-15 00:18:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 922 bytes |
コンパイル時間 | 1,204 ms |
コンパイル使用メモリ | 116,408 KB |
最終ジャッジ日時 | 2025-01-08 11:34:38 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <iomanip> #include <cmath> #include <unordered_map> using namespace std; using ll = long long; constexpr ll MOD = 1e9 + 7; constexpr int INF = 1 << 30; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; vector<int> a(N); for(int i = 0; i < N; ++i) cin >> a[i]; unordered_map<ll, ll> dp; for(int i = 0; i < N; ++i) { unordered_map<ll, ll> tmp; for(auto itr = dp.begin(); itr != dp.end(); ++itr) { if(itr->first == 0) { tmp[a[i]] += itr->second; } else { tmp[gcd(itr->first, a[i])] += itr->second; } tmp[itr->first] += itr->second; } swap(dp, tmp); if (!dp[a[i]]) { dp[a[i]] = 1; } if (!dp[0]) { dp[0] = 1; } } cout << dp[1] << '\n'; return 0; }