結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-13 14:22:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 583 bytes |
| コンパイル時間 | 911 ms |
| コンパイル使用メモリ | 84,424 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 11:02:40 |
| 合計ジャッジ時間 | 2,001 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <vector>
#include <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];
map<int, ll> dp;
for (int x : a) {
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;
}