結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
|
| 提出日時 | 2021-07-08 11:40:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 442 ms / 2,000 ms |
| コード長 | 674 bytes |
| コンパイル時間 | 587 ms |
| コンパイル使用メモリ | 71,328 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 12:29:05 |
| 合計ジャッジ時間 | 2,173 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX=300010;
int d[MAX];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
vector<int> a(n);
for ( int i=0; i<n; i++ ) cin>>a[i];
for ( int i=0; i<n; i++ ) {
int res=1;
for ( int j=1; j*j<=a[i]; j++ ) {
if ( j<a[i] && a[i]%j==0 ) {
res=max(res,d[j]+1);
if ( a[i]/j<a[i] && a[i]/j!=j ) res=max(res,d[a[i]/j]+1);
}
}
d[a[i]]=max(d[a[i]],res);
}
int ans=0;
for ( int i=1; i<MAX; i++ ) ans=max(ans,d[i]);
cout<<ans<<'\n';
return 0;
}