結果

問題 No.390 最長の数列
ユーザー nemutainemutai
提出日時 2023-03-28 09:53:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 632 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 169,368 KB
実行使用メモリ 19,116 KB
最終ジャッジ日時 2023-10-20 05:26:28
合計ジャッジ時間 3,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
19,116 KB
testcase_01 AC 12 ms
19,116 KB
testcase_02 AC 13 ms
19,116 KB
testcase_03 AC 13 ms
19,116 KB
testcase_04 AC 13 ms
19,116 KB
testcase_05 AC 40 ms
19,116 KB
testcase_06 AC 109 ms
19,116 KB
testcase_07 AC 12 ms
19,116 KB
testcase_08 AC 10 ms
19,116 KB
testcase_09 AC 12 ms
19,116 KB
testcase_10 AC 58 ms
19,116 KB
testcase_11 AC 57 ms
19,116 KB
testcase_12 AC 56 ms
19,116 KB
testcase_13 AC 42 ms
19,116 KB
testcase_14 AC 74 ms
19,116 KB
testcase_15 AC 11 ms
19,116 KB
testcase_16 AC 10 ms
19,116 KB
testcase_17 AC 12 ms
19,116 KB
testcase_18 AC 14 ms
19,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;

int main(){
    ll N;
    cin>>N;
    vll A(1e6+1);
    for(int i=0;i<N;i++){
        ll a;
        cin>>a;
        A[a]++;
    }

    vll dp(A.size(),-1);
    for(int i=1;i<=1e6;i++){
        if(!A[i])continue;
        if(dp[i]==-1)dp[i]=1;
        for(int j=2;i*j<=1e6;j++){
            if(!A[i*j])continue;
            dp[i*j]=max(dp[i*j],dp[i]+1);
        }
    }
    ll ans=0;
    for(auto x:dp) ans=max(ans,x);
    cout << ans << endl;
}
0