結果

問題 No.390 最長の数列
ユーザー Ai3ShotaAi3Shota
提出日時 2018-05-11 04:46:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 364 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 149,676 KB
実行使用メモリ 7,940 KB
最終ジャッジ日時 2023-09-10 12:15:17
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,372 KB
testcase_01 AC 2 ms
5,464 KB
testcase_02 AC 2 ms
5,380 KB
testcase_03 AC 3 ms
5,380 KB
testcase_04 AC 3 ms
5,496 KB
testcase_05 AC 364 ms
5,816 KB
testcase_06 AC 266 ms
7,940 KB
testcase_07 AC 3 ms
5,392 KB
testcase_08 AC 2 ms
5,396 KB
testcase_09 AC 3 ms
5,476 KB
testcase_10 AC 272 ms
7,936 KB
testcase_11 AC 272 ms
7,628 KB
testcase_12 AC 273 ms
7,852 KB
testcase_13 AC 183 ms
7,552 KB
testcase_14 AC 124 ms
6,004 KB
testcase_15 AC 3 ms
5,392 KB
testcase_16 AC 3 ms
5,536 KB
testcase_17 AC 16 ms
7,420 KB
testcase_18 AC 24 ms
7,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

int N;
int num[100001] = {0};
int dp[1000001] = {0};

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

int main(void){
    
    cin >> N;
    
    int i;
    for(i = 0; i < N; ++i){
        cin >> num[i];
    }
    sort(num, num + N);
    
    for(auto i : num){
        dp[i] = 1;
        auto k = divisor(i);
        for(auto j : k) dp[i] = max(dp[i], dp[j] + 1);
    }
    
    int result = 0;
    for(i = 0; i < N; ++i) result = max(result, dp[num[i]]);
    
    cout << result << endl;
    
    return 0;
}
0