結果
問題 | No.979 Longest Divisor Sequence |
ユーザー |
![]() |
提出日時 | 2020-01-31 21:53:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,502 ms / 2,000 ms |
コード長 | 901 bytes |
コンパイル時間 | 1,733 ms |
コンパイル使用メモリ | 179,032 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-09-17 07:59:05 |
合計ジャッジ時間 | 4,333 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; map<int,int> mp; int ans = 1; for(int i=0;i<n;i++){ if(a[i] != 1 && mp.count(1)){ mp[a[i]] = max(mp[a[i]],mp[1]+1); } for(int j=2;j*j<=a[i];j++){ if(a[i]%j==0){ if(mp.count(j)){ mp[a[i]] = max(mp[a[i]],mp[j]+1); } if(j*j != a[i] && mp.count(a[i]/j)){ mp[a[i]] = max(mp[a[i]],mp[a[i]/j]+1); } } } mp[a[i]] = max(1,mp[a[i]]); //cerr << a[i] << " " << mp[a[i]] << endl; } for(auto i:mp){ ans = max(ans,i.second); } cout << ans << endl; }