結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2023-03-28 09:53:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 102 ms / 5,000 ms |
コード長 | 632 bytes |
コンパイル時間 | 1,390 ms |
コンパイル使用メモリ | 168,272 KB |
実行使用メモリ | 18,944 KB |
最終ジャッジ日時 | 2024-09-20 01:07:34 |
合計ジャッジ時間 | 2,734 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define all(v) v.begin(),v.end() using ll = long long; using ull = unsigned long long; using vll=vector<ll>; using vvll = vector<vector<ll>>; int main(){ ll N; cin>>N; vll A(1e6+1); for(int i=0;i<N;i++){ ll a; cin>>a; A[a]++; } vll dp(A.size(),-1); for(int i=1;i<=1e6;i++){ if(!A[i])continue; if(dp[i]==-1)dp[i]=1; for(int j=2;i*j<=1e6;j++){ if(!A[i*j])continue; dp[i*j]=max(dp[i*j],dp[i]+1); } } ll ans=0; for(auto x:dp) ans=max(ans,x); cout << ans << endl; }