結果

問題 No.390 最長の数列
ユーザー finefine
提出日時 2016-07-09 00:43:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 630 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 43,056 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-21 09:01:38
合計ジャッジ時間 1,318 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 16 ms
5,376 KB
testcase_06 AC 44 ms
7,884 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 40 ms
7,936 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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) {
            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