結果

問題 No.2218 Multiple LIS
ユーザー Ricky_ponRicky_pon
提出日時 2023-02-17 22:53:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 3,000 ms
コード長 3,998 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 144,184 KB
実行使用メモリ 4,736 KB
最終ジャッジ日時 2023-09-26 20:14:22
合計ジャッジ時間 4,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 19 ms
4,380 KB
testcase_23 AC 30 ms
4,380 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 34 ms
4,384 KB
testcase_26 AC 47 ms
4,616 KB
testcase_27 AC 46 ms
4,736 KB
testcase_28 AC 47 ms
4,488 KB
testcase_29 AC 46 ms
4,592 KB
testcase_30 AC 47 ms
4,536 KB
testcase_31 AC 46 ms
4,472 KB
testcase_32 AC 46 ms
4,472 KB
testcase_33 AC 46 ms
4,468 KB
testcase_34 AC 46 ms
4,444 KB
testcase_35 AC 46 ms
4,436 KB
testcase_36 AC 14 ms
4,460 KB
testcase_37 AC 64 ms
4,492 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 66 ms
4,532 KB
testcase_41 AC 69 ms
4,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <bits/stdc++.h>
#include <string.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define For(i, a, b) for (int i = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second


#include <algorithm>
#include <bitset>
#include <vector>

namespace rklib {

struct SimpleSieve {
    std::vector<bool> is_prime;
    std::vector<int> prime;

    SimpleSieve(int n) {
        is_prime.resize(n + 1, true);
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i <= n; ++i) {
            if (!is_prime[i]) continue;
            prime.push_back(i);
            for (int j = 2; i * j <= n; ++j) {
                is_prime[i * j] = false;
            }
        }
    }
};

struct Sieve {
    std::vector<int> min_factor, prime;

    Sieve(int n) {
        min_factor.resize(n + 1, 0);
        for (int i = 2; i <= n; ++i) {
            if (min_factor[i] == 0) {
                min_factor[i] = i;
                prime.push_back(i);
            }
            for (int x : prime) {
                if (x * i > n || x > i) break;
                min_factor[x * i] = x;
            }
        }
    }

    std::vector<std::pair<int, int>> prime_factor(int n) {
        std::vector<std::pair<int, int>> res;
        while (n > 1) {
            if (res.empty() || res.rbegin()->first != min_factor[n]) {
                res.emplace_back(min_factor[n], 1);
            } else
                ++res.rbegin()->second;
            n /= min_factor[n];
        }
        return res;
    }

    void divisor_dfs(std::vector<std::pair<int, int>> &p, int t, int cur,
                     std::vector<int> &res) {
        if (cur == (int)p.size()) {
            res.push_back(t);
            return;
        }
        divisor_dfs(p, t, cur + 1, res);
        for (int _ = 0; _ < p[cur].second; ++_) {
            t *= p[cur].first;
            divisor_dfs(p, t, cur + 1, res);
        }
    }

    std::vector<int> get_divisor(int n, bool sorted = false) {
        std::vector<int> res;
        auto p = prime_factor(n);
        divisor_dfs(p, 1, 0, res);
        if (sorted) sort(res.begin(), res.end());
        return res;
    }
};

}  // namespace rklib


#include <algorithm>
#include <cassert>
#include <vector>

namespace rklib {

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

template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool chmin_non_negative(T &a, const T &b) {
    if (a < 0 || a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}

template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

}  // namespace rklib


using namespace std;
using namespace rklib;

using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);

    constexpr int MAX = 100'010;
    Sieve sv(MAX);
    int dp[MAX];
    memset(dp, 0, sizeof(dp));
    rep(i, n) {
        auto ds = sv.get_divisor(a[i]);
        int tmp = 0;
        for (auto d : ds) chmax(tmp, dp[d] + 1);
        dp[a[i]] = tmp;
    }
    printf("%d\n", *max_element(dp, dp + MAX));
}
0