結果

問題 No.390 最長の数列
ユーザー face4face4
提出日時 2018-08-27 20:25:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 469 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 65,444 KB
実行使用メモリ 7,968 KB
最終ジャッジ日時 2023-09-18 13:30:50
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 32 ms
4,380 KB
testcase_06 AC 63 ms
7,648 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 38 ms
7,932 KB
testcase_11 AC 38 ms
7,724 KB
testcase_12 AC 38 ms
7,968 KB
testcase_13 AC 33 ms
7,544 KB
testcase_14 AC 40 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 6 ms
7,260 KB
testcase_18 AC 7 ms
7,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int dp[1000001] = {};

int main(){
    int n;
    cin >> n;

    int x[n];
    for(int i = 0; i < n; i++)  cin >> x[i];

    for(int i : x)  dp[i] = 1;

    int ans = 0;
    for(int i = 1; i < 1000001; i++){
        if(!dp[i])   continue;
        for(int j = i+i; j < 1000001; j += i){
            if(dp[j])   dp[j] = max(dp[j], dp[i]+1);
        }
        ans = max(ans, dp[i]);
    }

    cout << ans << endl;

    return 0;
}
0