結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-11-13 10:12:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 123 ms / 5,000 ms |
| コード長 | 957 bytes |
| コンパイル時間 | 2,355 ms |
| コンパイル使用メモリ | 202,856 KB |
| 最終ジャッジ日時 | 2025-01-06 16:34:11 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T>
vector<T> compress(vector<T> v){
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
return v;
}
template<typename T>
map<T, Int> dict(const vector<T> &v){
map<T, Int> res;
for(Int i=0;i<(Int)v.size();i++)
res[v[i]]=i;
return res;
}
//INSERT ABOVE HERE
signed main(){
Int n;
cin>>n;
vector<Int> x(n);
for(Int i=0;i<n;i++) cin>>x[i];
x=compress(x);
const Int MAX = 1e6+100;
const Int INF = 1e9;
vector<Int> dp(MAX,-INF),ex(MAX,0);
for(Int a:x) ex[a]=1;
for(Int a:x){
chmax(dp[a],1);
for(Int b=a+a;b<MAX;b+=a)
if(ex[b]) chmax(dp[b],dp[a]+1);
}
Int ans=0;
for(Int i=0;i<MAX;i++) chmax(ans,dp[i]);
cout<<ans<<endl;
return 0;
}
beet