結果
問題 | No.979 Longest Divisor Sequence |
ユーザー | Mister |
提出日時 | 2020-01-31 22:01:58 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 469 ms / 2,000 ms |
コード長 | 754 bytes |
コンパイル時間 | 812 ms |
コンパイル使用メモリ | 131,224 KB |
実行使用メモリ | 36,992 KB |
最終ジャッジ日時 | 2024-11-30 16:19:12 |
合計ジャッジ時間 | 7,875 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#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; }