結果

問題 No.917 Make One With GCD
コンテスト
ユーザー beet
提出日時 2019-10-25 21:38:16
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 157µs
コード長 642 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,558 ms
コンパイル使用メモリ 220,852 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-24 12:10:04
合計ジャッジ時間 4,317 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  Int ans=0;
  for(Int l=0;l<n;l++){
    map<Int, Int> dp;
    dp[as[l]]=1;
    for(Int i=l+1;i<n;i++){
      map<Int, Int> nx;
      for(auto p:dp)
        nx[__gcd(p.first,as[i])]+=p.second;

      for(auto p:nx)
        dp[p.first]+=p.second;
    }
    ans+=dp[1];
  }

  cout<<ans<<endl;
  return 0;
}
0