結果
問題 |
No.979 Longest Divisor Sequence
|
ユーザー |
|
提出日時 | 2020-07-25 23:45:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,245 ms / 2,000 ms |
コード長 | 673 bytes |
コンパイル時間 | 1,921 ms |
コンパイル使用メモリ | 191,496 KB |
最終ジャッジ日時 | 2025-01-12 05:40:13 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i=0; i<n; i++) #define pb push_back #define int long long int N; int A[300010]; int dp[300010]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; rep(i, N) cin >> A[i]; for (auto& Ai:A) { dp[Ai] = 1; if (Ai==1) continue; int i = 1; while (i*i<=Ai) { if (Ai%i==0) { if (i==1) dp[Ai] = max(dp[Ai], dp[i]+1); else dp[Ai] = max({dp[Ai], dp[i]+1, dp[Ai/i]+1}); } i++; } } int ans = 0; rep(i, 300010) ans = max(ans, dp[i]); cout << ans << endl; }