結果

問題 No.2218 Multiple LIS
コンテスト
ユーザー HIcoder
提出日時 2023-07-11 16:10:36
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 125 ms / 3,000 ms
コード長 1,270 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 649 ms
コンパイル使用メモリ 117,524 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-07-01 18:17:46
合計ジャッジ時間 3,132 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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