結果

問題 No.917 Make One With GCD
ユーザー face4
提出日時 2019-10-25 23:31:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 426 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 77,852 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 11:06:01
合計ジャッジ時間 1,777 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<map>
using namespace std;

int gcd(int a, int b){
    return b==0 ? a : gcd(b, a%b);
}

typedef long long ll;

int main(){
    int n;
    cin >> n;
    map<int,ll> dp;
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        map<int,ll> ndp = dp;
        int x;  cin >> x;
        for(auto p : dp)    ndp[gcd(p.first,x)] += p.second;
        dp = ndp;
    }
    cout << dp[1] << endl;
    return 0;
}
0