結果

問題 No.390 最長の数列
ユーザー finefine
提出日時 2016-07-09 00:47:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 645 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 42,832 KB
実行使用メモリ 8,016 KB
最終ジャッジ日時 2024-04-10 08:54:08
合計ジャッジ時間 1,119 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 13 ms
6,940 KB
testcase_06 AC 43 ms
7,984 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 21 ms
8,016 KB
testcase_11 AC 19 ms
7,880 KB
testcase_12 AC 21 ms
8,012 KB
testcase_13 AC 18 ms
7,828 KB
testcase_14 AC 14 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 5 ms
7,752 KB
testcase_18 AC 4 ms
7,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX_N = 100000;
const int MAX_X = 1000000;
int x[MAX_N], dp[MAX_X + 1] = {};

int main() {
    int n;
    scanf("%d", &n);
    int xmax = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &x[i]);
        xmax = max(xmax, x[i]);
        dp[x[i]] = 1;
    }
    for (int i = 1; i <= xmax; i++) {
        if (dp[i] == 0) continue;
        for (int j = i * 2; j <= xmax; j += i) {
            if (dp[j] > 0) dp[j] = max(dp[j], dp[i] + 1);
        }
    }
    int res = 0;
    for (int i = 0; i < n; i++) res = max(res, dp[x[i]]);
    printf("%d\n", res);
    return 0;
}
0