結果

問題 No.390 最長の数列
ユーザー fine
提出日時 2016-07-09 00:47:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 645 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 41,668 KB
実行使用メモリ 7,496 KB
最終ジャッジ日時 2024-10-02 10:38:12
合計ジャッジ時間 1,246 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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