結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
![]() |
提出日時 | 2020-02-01 00:07:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 461 ms / 2,000 ms |
コード長 | 867 bytes |
コンパイル時間 | 826 ms |
コンパイル使用メモリ | 77,484 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 11:49:34 |
合計ジャッジ時間 | 2,110 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> dp(n), b((int)3e+5 + 1, -1); int r = 0; for (int i = 0; i < n; i++) { int t; cin >> t; int s = 0; if (t > 1) { if (b[1] >= 0) s = max(s, dp[b[1]]); for (int k = 2; k * k <= t; k++) { if (t % k == 0) { int l = t / k; if (b[k] >= 0) s = max(s, dp[b[k]]); if (b[l] >= 0) s = max(s, dp[b[l]]); } } } b[t] = i; dp[i] = s + 1; r = max(r, dp[i]); } cout << r << endl; return 0; }