結果

問題 No.2218 Multiple LIS
ユーザー HIcoder
提出日時 2023-07-11 16:10:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 390 ms / 3,000 ms
コード長 1,270 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 101,980 KB
最終ジャッジ日時 2025-02-15 09:49:19
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    vector<int> dp(N,0);
    
    //map<int,int> mp;
    vector<int> mp(100000+10,0);
    mp[A[0]]=1;

    for(int i=1;i<N;i++){
        vector<ll> prev; 
        for(ll d=1;d*d<=A[i];d++){
            if(A[i]%d==0){
                //A[i]がdで割れるとき
                prev.push_back(d);
                

                dp[i]=max(dp[i],mp[d]+1);
                if(A[i]/d!=d){
                    ll v=A[i]/d;
                    dp[i]=max(dp[i],mp[v]+1);
                    prev.push_back(v);

                }
            }
        }

        /*
        for(ll d:prev){
            mp[d]=max(mp[d],dp[i]);
        }
        */
        mp[A[i]]=max(mp[A[i]],dp[i]);

    }

    int ans=1;

    for(int i=0;i<N;i++){
        //cout<<"dp["<<i<<"]="<<dp[i]<<endl;
        ans=max(dp[i],ans);
    }

    cout<<ans<<endl;

}
0