結果

問題 No.390 最長の数列
ユーザー Ronlynes
提出日時 2017-09-08 17:11:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 372 ms / 5,000 ms
コード長 825 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 64,892 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-11-07 05:04:21
合計ジャッジ時間 3,936 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

int main(void){
    int n, a[100005];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    int dp[1000006];
    int m = 1;
    for(int i=0; i<n; i++){
        dp[a[i]] = 1;
        if(a[i] != 1){
            vector<int> res = divisor(a[i]);
            for(int j=0; j<res.size(); j++){
                dp[a[i]] = max(dp[a[i]], dp[res[j]]+1);
                m = max(m, dp[a[i]]);
            }
        }
    }
    cout << m << endl;


    return 0;
}
0