結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2017-12-22 16:13:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,104 ms / 5,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 946 ms |
コンパイル使用メモリ | 78,416 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-12-17 23:13:13 |
合計ジャッジ時間 | 6,853 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include<iostream> #include<algorithm> #include<vector> using namespace std; vector<long long> divisor(long long n) { vector<long long> s; for (long long i = 1; i*i<= n; i++) { if (n%i == 0) { s.push_back(i); if (i*i != n) { s.push_back(n / i); } } } sort(s.begin(), s.end()); return s; } int main() { int n, i, x[101010], dp[1010101]; cin >> n; for (i = 1; i <= n; i++) { cin >> x[i]; } sort(x + 1, x + n + 1); for (i = 1; i <= n; i++) { dp[x[i]] = 1; } for (i = 1; i <= 1000001; i++) { if (dp[i]) { auto v = divisor(i); for (auto j : v) { if(j != i) { dp[i] = max(dp[i], dp[j] + 1); } } } } int ans = 0; for (i = 1; i <= n; i++) { ans = max(ans, dp[x[i]]); } cout << ans << endl; }