結果

問題 No.390 最長の数列
ユーザー MisterMister
提出日時 2020-05-29 17:28:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,746 ms / 5,000 ms
コード長 738 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 93,672 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-23 14:51:52
合計ジャッジ時間 5,243 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 43 ms
8,704 KB
testcase_06 AC 1,746 ms
8,704 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 256 ms
8,832 KB
testcase_11 AC 271 ms
8,704 KB
testcase_12 AC 262 ms
8,704 KB
testcase_13 AC 379 ms
7,424 KB
testcase_14 AC 388 ms
8,832 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 9 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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::map<int, int> pos;
    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.count(y)) 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