結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
![]() |
提出日時 | 2019-10-07 21:50:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 202 ms / 2,000 ms |
コード長 | 845 bytes |
コンパイル時間 | 804 ms |
コンパイル使用メモリ | 74,752 KB |
実行使用メモリ | 17,408 KB |
最終ジャッジ日時 | 2024-10-14 17:04:14 |
合計ジャッジ時間 | 2,526 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#include <algorithm> #include <iostream> #include <vector> int main() { static constexpr int ALim = 300001; int n; std::cin >> n; std::vector<std::vector<int>> rev(ALim); std::vector<int> dp(ALim, -1); for (int i = 0; i != n; ++i) { int a; std::cin >> a; rev[a].push_back(i); dp[a] = i; } int len = 0; while ( std::any_of(dp.cbegin(), dp.cend(), [](const int x) { return x > -1; })) { ++len; for (int i = 1; i != ALim; ++i) { int max = -1; for (int j = i + i; j < ALim; j += i) { max = std::max(max, dp[j]); } int j = 0; const int size = rev[i].size(); while (j != size && rev[i][j] < max) { ++j; } if (j == 0) { dp[i] = -1; } else { dp[i] = rev[i][j - 1]; } } } std::cout << len << std::endl; }