結果
問題 | No.390 最長の数列 |
ユーザー |
![]() |
提出日時 | 2018-06-11 15:48:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,095 ms / 5,000 ms |
コード長 | 918 bytes |
コンパイル時間 | 887 ms |
コンパイル使用メモリ | 99,428 KB |
実行使用メモリ | 11,932 KB |
最終ジャッジ日時 | 2024-06-30 13:35:22 |
合計ジャッジ時間 | 6,746 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include <cmath> #include <iostream> #include <vector> #include <queue> #include <map> #include <set> #include <algorithm> #include <utility> #include <iomanip> #define int long long int #define rep(i, n) for(int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9+7; signed main(){ int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vector<int> dp(1e6 + 1); rep(i, n){ for(int j = 1; j * j <= a[i]; j++){ if(a[i] % j != 0){ continue; } dp[a[i]] = max(dp[a[i]], dp[j] + 1); if(j != 1){ dp[a[i]] = max(dp[a[i]], dp[a[i] / j] + 1); } } } int ans = 0; rep(i, 1e6+1){ if(ans < dp[i]){ ans = dp[i]; } } cout << ans << endl; return 0; }