結果

問題 No.390 最長の数列
ユーザー conf
提出日時 2016-07-09 00:07:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,767 ms / 5,000 ms
コード長 627 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 80,368 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-10-02 10:37:29
合計ジャッジ時間 6,337 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N;
    cin>>N;
    map<int,int> DP;
    int Xmax=0;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        DP[x]=1;
        Xmax=max(x,Xmax);
    }
    for(auto ite=DP.begin(); ite!=DP.end();ite++){
        int x=ite->first;
        for(int i=2;x*i<=Xmax;i++){
            if(DP.find(x*i)!=DP.end()){
                DP[x*i]=max(DP[x*i],DP[x]+1);
            }
        }
    }
    int ans=1;
    for(auto ite=DP.begin(); ite!=DP.end();ite++){
        ans=max(ans,ite->second);
    }
    cout<<ans<<endl;
    return 0;
}
0