結果

問題 No.390 最長の数列
ユーザー MisterMister
提出日時 2020-05-29 17:29:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 774 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 88,056 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-23 14:53:20
合計ジャッジ時間 1,956 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,188 KB
testcase_01 AC 5 ms
7,168 KB
testcase_02 AC 5 ms
7,040 KB
testcase_03 AC 4 ms
7,132 KB
testcase_04 AC 4 ms
7,168 KB
testcase_05 AC 22 ms
7,912 KB
testcase_06 AC 50 ms
7,936 KB
testcase_07 AC 5 ms
7,168 KB
testcase_08 AC 5 ms
7,204 KB
testcase_09 AC 5 ms
7,168 KB
testcase_10 AC 25 ms
7,928 KB
testcase_11 AC 26 ms
8,064 KB
testcase_12 AC 25 ms
8,008 KB
testcase_13 AC 19 ms
7,784 KB
testcase_14 AC 23 ms
7,936 KB
testcase_15 AC 5 ms
7,168 KB
testcase_16 AC 4 ms
7,168 KB
testcase_17 AC 6 ms
7,168 KB
testcase_18 AC 7 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int X = 1000000;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;
    std::sort(xs.rbegin(), xs.rend());

    std::vector<int> pos(X + 1, -1);
    for (int i = 0; i < n; ++i) pos[xs[i]] = i;

    std::vector<int> dp(n, 1);
    for (int i = 0; i < n; ++i) {
        auto x = xs[i];

        for (int y = x * 2; y <= xs.front(); y += x) {
            if (pos[y] == -1) continue;
            dp[i] = std::max(dp[i], dp[pos[y]] + 1);
        }
    }

    std::cout << *std::max_element(dp.begin(), dp.end()) << "\n";
}

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

    solve();

    return 0;
}
0