結果

問題 No.2218 Multiple LIS
ユーザー stoqstoq
提出日時 2022-06-18 00:31:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 3,000 ms
コード長 1,639 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 210,712 KB
実行使用メモリ 4,532 KB
最終ジャッジ日時 2023-09-14 14:47:53
合計ジャッジ時間 6,272 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 22 ms
4,380 KB
testcase_23 AC 34 ms
4,380 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 39 ms
4,376 KB
testcase_26 AC 53 ms
4,380 KB
testcase_27 AC 53 ms
4,376 KB
testcase_28 AC 54 ms
4,384 KB
testcase_29 AC 53 ms
4,412 KB
testcase_30 AC 53 ms
4,376 KB
testcase_31 AC 49 ms
4,380 KB
testcase_32 AC 50 ms
4,376 KB
testcase_33 AC 50 ms
4,532 KB
testcase_34 AC 50 ms
4,376 KB
testcase_35 AC 49 ms
4,380 KB
testcase_36 AC 12 ms
4,380 KB
testcase_37 AC 70 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 69 ms
4,376 KB
testcase_41 AC 67 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

template <typename T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const int MAX_N = 1e5 + 10;
int min_factor[MAX_N] = {};

struct init_prime {
  init_prime() {
    min_factor[1] = -1;
    for (int i = 2; i < MAX_N; i++) {
      if (min_factor[i] != 0) continue;
      for (int j = i + i; j < MAX_N; j += i) min_factor[j] = i;
    }
  }
} init_prime;

void factorization(int n, unordered_map<int, int> &res) {
  if (n <= 1) return;
  if (!min_factor[n]) {
    ++res[n];
    return;
  }
  ++res[min_factor[n]];
  factorization(n / min_factor[n], res);
}

void dfs(unordered_map<int, int>::iterator itr, int prod,
         unordered_map<int, int> &mp, vector<int> &res) {
  if (itr == mp.end()) {
    res.emplace_back(prod);
    return;
  }
  auto [p, e] = *itr;
  for (int i = 0; i <= e; i++) {
    dfs(next(itr), prod, mp, res);
    prod *= p;
  }
}
vector<int> divisors(int n) {
  unordered_map<int, int> mp;
  factorization(n, mp);
  vector<int> res;
  dfs(mp.begin(), 1, mp, res);
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &&t : a) cin >> t;
  vector<int> dp(100010, 0);
  for (int i = 0; i < n; i++) {
    int Max = 0;
    vector<int> ds = divisors(a[i]);
    for (auto d : ds) chmax(Max, dp[d]);
    dp[a[i]] = Max + 1;
  }
  cout << *max_element(begin(dp), end(dp)) << "\n";
}
0