結果
問題 | No.979 Longest Divisor Sequence |
ユーザー |
![]() |
提出日時 | 2020-01-31 22:15:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 395 ms / 2,000 ms |
コード長 | 841 bytes |
コンパイル時間 | 1,471 ms |
コンパイル使用メモリ | 172,644 KB |
実行使用メモリ | 39,344 KB |
最終ジャッジ日時 | 2024-09-17 08:35:47 |
合計ジャッジ時間 | 7,516 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; auto chmax = [](auto&& l, auto r) { return l < r ? l = r, 1 : 0; }; constexpr int lim = 3e5, th = lim + 1; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for_each(begin(a), end(a), [](int& e) { cin >> e; }); reverse(begin(a), end(a)); vector<vector<int>> ds(lim + 1); for (int d = 1; d < th; ++d) { for (int i = 2 * d; i <= lim; i += d) { ds[i].push_back(d); } } vector<int> dp(lim + 1), m(th); for (int e : a) { int mx = -1; if (e < th) { mx = m[e]; } else { for (int i = 2 * e; i <= lim; i += e) { chmax(mx, dp[i]); } } chmax(dp[e], mx + 1); for (int d : ds[e]) { chmax(m[d], dp[e]); } } cout << *max_element(begin(dp), end(dp)) << '\n'; }