結果

問題 No.390 最長の数列
ユーザー NagisaNagisa
提出日時 2016-07-13 18:56:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 424 ms / 5,000 ms
コード長 850 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 169,256 KB
実行使用メモリ 7,816 KB
最終ジャッジ日時 2024-04-10 09:08:17
合計ジャッジ時間 4,445 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 424 ms
6,944 KB
testcase_06 AC 315 ms
7,816 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 311 ms
7,768 KB
testcase_11 AC 308 ms
7,680 KB
testcase_12 AC 306 ms
7,692 KB
testcase_13 AC 214 ms
7,692 KB
testcase_14 AC 140 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 4 ms
6,944 KB
testcase_17 AC 17 ms
7,340 KB
testcase_18 AC 26 ms
7,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
int dp[1000010] = {};

vector<int> getDivisor(int n){
    vector<int> v;
    for(int i=1; i*i<=n; i++){
        if(n%i==0){
            v.push_back(i);
            if(i!=n/i){
                v.push_back(n/i);
            }
        }
    }
    sort(v.begin(),v.end());
    return v;
}

int main(){
    int N;
    cin >> N;
    int temp = 0;
    vector<int> a;
    REP(i,N){
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(),a.end());
    for(auto p: a){
        temp = 1;
        for(auto q: getDivisor(p)){
            if(p==q) continue;
            temp = max(temp,dp[q]+1);
        }
        dp[p] = temp;
    }
    int ans = 0;
    REP(i,1000010){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}
0