結果

問題 No.390 最長の数列
ユーザー sugarrrsugarrr
提出日時 2018-03-11 08:57:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 400 ms / 5,000 ms
コード長 1,246 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 85,388 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-23 00:57:07
合計ジャッジ時間 3,213 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,296 KB
testcase_01 AC 5 ms
7,424 KB
testcase_02 AC 5 ms
7,296 KB
testcase_03 AC 5 ms
7,296 KB
testcase_04 AC 5 ms
7,168 KB
testcase_05 AC 400 ms
7,680 KB
testcase_06 AC 277 ms
7,808 KB
testcase_07 AC 5 ms
7,296 KB
testcase_08 AC 5 ms
7,168 KB
testcase_09 AC 6 ms
7,424 KB
testcase_10 AC 290 ms
7,808 KB
testcase_11 AC 288 ms
7,808 KB
testcase_12 AC 288 ms
7,680 KB
testcase_13 AC 203 ms
7,552 KB
testcase_14 AC 129 ms
7,808 KB
testcase_15 AC 5 ms
7,296 KB
testcase_16 AC 5 ms
7,296 KB
testcase_17 AC 18 ms
7,296 KB
testcase_18 AC 26 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)
const double EPS=1E-8;

////////////////////////////////////////

vector<int> div(int n){
    vector<int>v;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            v.push_back(i);
            if(i*i!=n&&i!=n)v.push_back(n/i);
        }
    }
    return v;
}


int main(){
    int n;cin>>n;
    int x[n+1];rep(i,0,n-1)cin>>x[i];
    sort(x,x+n);x[n]=inf;
    int dp[1000005];memset(dp,0,sizeof(dp));
    int pos=1;
    dp[x[0]]=1;
    rep(i,2,1000000){
        if(x[pos]==i){
            for(auto x:div(i)){
                if(x==i)continue;
                dp[i]=max(dp[i],dp[x]+1);
            }
            pos++;
        }
    }
    int ans=0;
    rep(i,1,1000000)ans=max(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}

0