結果

問題 No.2218 Multiple LIS
ユーザー HIcoderHIcoder
提出日時 2023-07-11 16:10:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 413 ms / 3,000 ms
コード長 1,270 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 103,348 KB
実行使用メモリ 4,752 KB
最終ジャッジ日時 2023-10-11 07:11:29
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 17 ms
4,348 KB
testcase_22 AC 104 ms
4,348 KB
testcase_23 AC 177 ms
4,352 KB
testcase_24 AC 37 ms
4,352 KB
testcase_25 AC 197 ms
4,352 KB
testcase_26 AC 280 ms
4,564 KB
testcase_27 AC 283 ms
4,508 KB
testcase_28 AC 281 ms
4,532 KB
testcase_29 AC 279 ms
4,632 KB
testcase_30 AC 279 ms
4,752 KB
testcase_31 AC 98 ms
4,508 KB
testcase_32 AC 98 ms
4,572 KB
testcase_33 AC 98 ms
4,584 KB
testcase_34 AC 97 ms
4,556 KB
testcase_35 AC 98 ms
4,508 KB
testcase_36 AC 22 ms
4,560 KB
testcase_37 AC 413 ms
4,632 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 331 ms
4,628 KB
testcase_41 AC 331 ms
4,512 KB
権限があれば一括ダウンロードができます

ソースコード

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