結果

問題 No.390 最長の数列
ユーザー RonlynesRonlynes
提出日時 2017-09-08 17:11:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 330 ms / 5,000 ms
コード長 825 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 65,168 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-24 20:11:09
合計ジャッジ時間 3,905 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,680 KB
testcase_01 AC 4 ms
7,808 KB
testcase_02 AC 3 ms
7,808 KB
testcase_03 AC 4 ms
7,680 KB
testcase_04 AC 4 ms
7,680 KB
testcase_05 AC 330 ms
7,680 KB
testcase_06 AC 244 ms
7,808 KB
testcase_07 AC 4 ms
7,680 KB
testcase_08 AC 4 ms
7,808 KB
testcase_09 AC 4 ms
7,552 KB
testcase_10 AC 252 ms
7,808 KB
testcase_11 AC 256 ms
7,680 KB
testcase_12 AC 245 ms
7,808 KB
testcase_13 AC 163 ms
7,808 KB
testcase_14 AC 114 ms
7,808 KB
testcase_15 AC 4 ms
7,552 KB
testcase_16 AC 4 ms
7,808 KB
testcase_17 AC 15 ms
7,680 KB
testcase_18 AC 22 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

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