結果

問題 No.390 最長の数列
ユーザー dnishdnish
提出日時 2018-06-20 17:11:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 5,000 ms
コード長 1,019 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 171,428 KB
実行使用メモリ 7,724 KB
最終ジャッジ日時 2023-09-13 07:22:17
合計ジャッジ時間 5,175 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,576 KB
testcase_01 AC 3 ms
5,536 KB
testcase_02 AC 3 ms
5,332 KB
testcase_03 AC 3 ms
5,336 KB
testcase_04 AC 3 ms
5,384 KB
testcase_05 AC 372 ms
5,720 KB
testcase_06 AC 296 ms
7,632 KB
testcase_07 AC 3 ms
5,432 KB
testcase_08 AC 3 ms
5,404 KB
testcase_09 AC 3 ms
5,392 KB
testcase_10 AC 281 ms
7,688 KB
testcase_11 AC 281 ms
7,692 KB
testcase_12 AC 281 ms
7,724 KB
testcase_13 AC 184 ms
7,540 KB
testcase_14 AC 130 ms
6,216 KB
testcase_15 AC 4 ms
5,452 KB
testcase_16 AC 3 ms
5,648 KB
testcase_17 AC 17 ms
7,408 KB
testcase_18 AC 24 ms
7,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define REP(i,n,N) for(int i=(n); i<(N); i++)
#define RREP(i,n,N) for(int i=(N-1); i>=n; i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll inf=1e18+7;

int n;
int x[100010];
int dp[1000010];
int main() {
    cin>>n;
    REP(i,0,n) cin>>x[i];
    sort(x,x+n);
    int ans=0;
    REP(i,0,n){
        dp[x[i]]=1;
    }
    REP(i,2,1000001){
        if(dp[i]){
            vector<int> vi;
            vi.push_back(1);
            for(int j=2;j*j<=i;j++){
                if(i%j==0){
                    vi.push_back(j);
                    if(j*j!=i) vi.push_back(i/j);
                }
            }
            sort(ALL(vi));
            for(auto v:vi){
                dp[i] = max(dp[i], dp[v]+1);
            }
        }
    }
    REP(i,0,n){
        ans=max(ans, dp[x[i]]);
    }
    p(ans);
    return 0;
}
0