結果

問題 No.979 Longest Divisor Sequence
ユーザー MisterMister
提出日時 2020-01-31 22:01:58
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 95,016 KB
実行使用メモリ 36,988 KB
最終ジャッジ日時 2023-08-20 13:49:32
合計ジャッジ時間 9,364 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 476 ms
36,868 KB
testcase_01 AC 389 ms
36,916 KB
testcase_02 AC 399 ms
36,880 KB
testcase_03 AC 445 ms
36,972 KB
testcase_04 AC 438 ms
36,968 KB
testcase_05 AC 484 ms
36,904 KB
testcase_06 AC 427 ms
36,948 KB
testcase_07 AC 423 ms
36,964 KB
testcase_08 AC 372 ms
36,848 KB
testcase_09 AC 337 ms
36,972 KB
testcase_10 AC 354 ms
36,856 KB
testcase_11 AC 368 ms
36,936 KB
testcase_12 AC 402 ms
36,968 KB
testcase_13 AC 493 ms
36,904 KB
testcase_14 AC 597 ms
36,880 KB
testcase_15 AC 490 ms
36,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

constexpr int X = 300000;

void solve() {
    std::vector<std::vector<int>> facts(X + 1);
    for (int p = 1; p <= X; ++p) {
        for (int q = 2; p * q <= X; ++q) {
            facts[p * q].push_back(p);
        }
    }

    int n;
    std::cin >> n;

    std::vector<int> dp(X + 1, -n);
    while (n--) {
        int a;
        std::cin >> a;

        dp[a] = std::max(dp[a], 1);
        for (auto p : facts[a]) {
            dp[a] = std::max(dp[a], dp[p] + 1);
        }
    }

    std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0