結果

問題 No.2218 Multiple LIS
ユーザー hiro71687khiro71687k
提出日時 2023-02-25 18:27:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 3,000 ms
コード長 3,113 bytes
コンパイル時間 4,446 ms
コンパイル使用メモリ 266,320 KB
実行使用メモリ 12,860 KB
最終ジャッジ日時 2023-10-11 15:28:37
合計ジャッジ時間 8,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
10,228 KB
testcase_01 AC 18 ms
10,168 KB
testcase_02 AC 17 ms
10,208 KB
testcase_03 AC 19 ms
10,288 KB
testcase_04 AC 18 ms
10,100 KB
testcase_05 AC 17 ms
10,216 KB
testcase_06 AC 17 ms
10,212 KB
testcase_07 AC 18 ms
10,168 KB
testcase_08 AC 18 ms
10,212 KB
testcase_09 AC 18 ms
10,308 KB
testcase_10 AC 17 ms
10,308 KB
testcase_11 AC 18 ms
10,172 KB
testcase_12 AC 18 ms
10,220 KB
testcase_13 AC 19 ms
10,300 KB
testcase_14 AC 18 ms
10,300 KB
testcase_15 AC 17 ms
10,160 KB
testcase_16 AC 18 ms
10,164 KB
testcase_17 AC 18 ms
10,220 KB
testcase_18 AC 18 ms
10,208 KB
testcase_19 AC 18 ms
10,224 KB
testcase_20 AC 19 ms
10,344 KB
testcase_21 AC 23 ms
10,252 KB
testcase_22 AC 54 ms
10,868 KB
testcase_23 AC 83 ms
11,276 KB
testcase_24 AC 33 ms
10,228 KB
testcase_25 AC 92 ms
11,480 KB
testcase_26 AC 128 ms
12,076 KB
testcase_27 AC 127 ms
12,068 KB
testcase_28 AC 130 ms
12,076 KB
testcase_29 AC 129 ms
12,260 KB
testcase_30 AC 128 ms
12,012 KB
testcase_31 AC 103 ms
12,600 KB
testcase_32 AC 102 ms
12,544 KB
testcase_33 AC 103 ms
12,860 KB
testcase_34 AC 103 ms
12,540 KB
testcase_35 AC 103 ms
12,592 KB
testcase_36 AC 43 ms
12,588 KB
testcase_37 AC 109 ms
12,596 KB
testcase_38 AC 18 ms
10,172 KB
testcase_39 AC 18 ms
10,240 KB
testcase_40 AC 105 ms
12,524 KB
testcase_41 AC 105 ms
12,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=double;
ld pie=3.14159265359;
ll mod=998244353;
ll inf=100000;
struct Eratosthenes {
    // テーブル
    vector<bool> isprime;

    // 整数 i を割り切る最小の素数
    vector<ll> minfactor;

    vector<ll>mobius;

    // コンストラクタで篩を回す
    Eratosthenes(ll N) : isprime(N+1, true),
                          minfactor(N+1, -1),
                          mobius(N+1,1) {
        // 1 は予めふるい落としておく
        isprime[1] = false;
        minfactor[1] = 1;

        // 篩
        for (ll p = 2; p <= N; ++p) {
            // すでに合成数であるものはスキップする
            if (!isprime[p]) continue;

            // p についての情報更新
            minfactor[p] = p;
            mobius[p]=-1;

            // p 以外の p の倍数から素数ラベルを剥奪
            for (ll q = p * 2; q <= N; q += p) {
                // q は合成数なのでふるい落とす
                isprime[q] = false;

                // q は p で割り切れる旨を更新
                if (minfactor[q] == -1) minfactor[q] = p;
                if ((q / p) % p == 0) mobius[q] = 0;
                else mobius[q] = -mobius[q];
            }
        }
    }

    // 高速素因数分解
    // pair (素因子, 指数) の vector を返す
    vector<pair<ll,ll>> factorize(ll n) {
        vector<pair<ll,ll>> res;
        while (n > 1) {
            ll p = minfactor[n];
            ll exp = 0;

            // n で割り切れる限り割る
            while (minfactor[n] == p) {
                n /= p;
                ++exp;
            }
            res.emplace_back(p, exp);
        }
        return res;
    }
    vector<ll>divisors(ll n){
        vector<ll>res({1});
        auto pf=factorize(n);
        for (auto p : pf)
        {
            ll s=(ll)res.size();
            for (ll i = 0; i < s; i++)
            {
                ll v=1;
                for (ll j = 0; j < p.second; j++)
                {
                    v*=p.first;
                    res.push_back(res[i]*v);
                }
                
            }
            
        }
        return res;
    }  
};
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    vector<vector<ll>>g(100001);
    Eratosthenes er(100001);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        g[a[i]].push_back(i);
    }
    for (ll i = 1; i <=100000; i++)
    {
        g[i].push_back(inf);
    }
    vector<ll>dp(n,0);
    dp[0]=1;
    for (ll i = 1; i < n; i++)
    {
        dp[i]=1;
        vector<ll>x=er.divisors(a[i]);
        for (ll j = 0; j < x.size(); j++)
        {
            ll v=lower_bound(g[x[j]].begin(),g[x[j]].end(),i)-g[x[j]].begin();
            if (v==0)
            {
                continue;
            }
            dp[i]=max(dp[i],dp[g[x[j]][v-1]]+1);
        }
    }
    ll ans=0;
    for (ll i = 0; i < dp.size(); i++)
    {
        ans=max(ans,dp[i]);
    }
    cout << ans << endl;
}
0