結果

問題 No.390 最長の数列
ユーザー vjudge1
提出日時 2025-04-20 16:58:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 516 bytes
コンパイル時間 1,749 ms
コンパイル使用メモリ 164,184 KB
実行使用メモリ 16,760 KB
最終ジャッジ日時 2025-04-20 16:59:01
合計ジャッジ時間 2,790 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int N=2e6+7;
const int M=1e6+7; 
int n,f[N],a[N];
bool vis[N];
signed main(){
//	freopen("sequence.in","r",stdin);
//	freopen("sequence.out","w",stdout);
    cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)f[a[i]]=1,vis[a[i]]=1;
	for(int i=1;i<=n;i++)for(int j=2;a[i]*j<M;j++)if(vis[j*a[i]])f[j*a[i]]=max(f[j*a[i]],f[a[i]]+1);
	int res=0;
	for(int i=1;i<=n;i++)res=max(res,f[a[i]]);
	cout<<res;
}
0