結果

問題 No.917 Make One With GCD
コンテスト
ユーザー iqueue02
提出日時 2020-02-21 17:13:59
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 619 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,019 ms
コンパイル使用メモリ 194,716 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-10 13:59:24
合計ジャッジ時間 1,851 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  auto GCD = [&](auto& f, int a, int b) -> int{
    if (b == 0) return a;
    return f(f,b,a%b);
  };
  vector<map<int, ll>> dp(n);
  ll res = 0;
  for (int i = 0; i < n; i++) {
    dp[i][a[i]]++;
    for (int j = i + 1; j < n; j++) {
      for (auto e : dp[i]) dp[j][GCD(GCD, a[j], e.first)] += e.second;
    }
    res += dp[i][1];
  }
  cout << res << endl;
  return 0;
}
0