結果
問題 | No.917 Make One With GCD |
ユーザー |
![]() |
提出日時 | 2019-10-27 19:19:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 570 bytes |
コンパイル時間 | 1,727 ms |
コンパイル使用メモリ | 178,440 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 11:10:05 |
合計ジャッジ時間 | 2,690 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include<bits/stdc++.h> #define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i) #define rep(i,a,b) for(int i=int(a);i<int(b);++i) #define All(x) (x).begin(),(x).end() using namespace std; typedef long long ll; ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数 int main(){ int N;cin>>N; vector<int> A(N); REP(i, N) cin >> A[i]; vector<map<int,ll>> dp(N+1); dp[0][0]=1; REP(i,N) for(auto e:dp[i]){ dp[i+1][gcd(e.first,A[i])]+=dp[i][e.first]; dp[i+1][e.first]+=dp[i][e.first]; } cout<<dp[N][1]<<endl; }