結果

問題 No.917 Make One With GCD
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-18 00:04:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 215,888 KB
実行使用メモリ 83,568 KB
最終ジャッジ日時 2023-09-06 16:49:41
合計ジャッジ時間 4,015 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
83,340 KB
testcase_01 AC 2 ms
5,408 KB
testcase_02 AC 2 ms
5,396 KB
testcase_03 AC 10 ms
44,480 KB
testcase_04 AC 8 ms
38,140 KB
testcase_05 AC 17 ms
81,272 KB
testcase_06 AC 26 ms
83,532 KB
testcase_07 AC 23 ms
83,400 KB
testcase_08 AC 7 ms
23,944 KB
testcase_09 AC 25 ms
83,400 KB
testcase_10 AC 25 ms
83,420 KB
testcase_11 AC 25 ms
83,376 KB
testcase_12 AC 28 ms
83,512 KB
testcase_13 AC 23 ms
83,416 KB
testcase_14 AC 24 ms
83,348 KB
testcase_15 AC 24 ms
83,348 KB
testcase_16 AC 23 ms
83,500 KB
testcase_17 AC 6 ms
21,888 KB
testcase_18 AC 18 ms
79,252 KB
testcase_19 AC 4 ms
11,592 KB
testcase_20 AC 8 ms
32,048 KB
testcase_21 AC 15 ms
60,748 KB
testcase_22 AC 10 ms
44,348 KB
testcase_23 AC 21 ms
83,568 KB
testcase_24 AC 15 ms
64,800 KB
testcase_25 AC 22 ms
83,444 KB
testcase_26 AC 5 ms
17,808 KB
testcase_27 AC 2 ms
9,672 KB
testcase_28 AC 3 ms
11,552 KB
testcase_29 AC 3 ms
11,644 KB
testcase_30 AC 6 ms
23,992 KB
testcase_31 AC 2 ms
7,488 KB
testcase_32 AC 3 ms
11,520 KB
testcase_33 AC 3 ms
9,564 KB
testcase_34 AC 2 ms
7,436 KB
testcase_35 AC 4 ms
13,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

vector<ll> divisor(ll n) {
  vector<ll> divs;
  for (ll i=1; i*i<=n; ++i) {
    if (n%i == 0) {
      divs.push_back(i);
      if (n/i != i) divs.push_back(n/i);
    }
  }
  return divs;
}


ll dp[60][500000];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  set<ll> divs;
  rep(i, n) {
    auto d = divisor(a[i]);
    for(auto e : d) divs.insert(e);
  }
  vector<ll> G;
  G.push_back(0);
  for(auto e : divs) {
    G.push_back(e);
  }
  int m = G.size();
  map<ll, int> idx;
  rep(i, m) idx[G[i]] = i;
  dp[0][0] = 1;
  rep(i, n) rep(j, m) {
    dp[i+1][j] += dp[i][j];
    dp[i+1][idx[gcd(G[j], a[i])]] += dp[i][j];
  }
  cout << dp[n][1] << '\n';
  return 0;
}
0