結果

問題 No.390 最長の数列
ユーザー vjudge1
提出日時 2025-04-18 16:57:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 1,382 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 194,224 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2025-04-18 16:57:10
合計ジャッジ時間 3,276 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
??????
??????
??????
??????
D P ????
??????
??????
??????
??????
??? l l?
??????
??????
?? OI ??
??????
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define eps 1e-9
//#define ENF 1e13
const int N=3e6;
const int mod=1e9+7;
inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
   while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
   return x*f;
}
void write(int x)
{
   if(x<0)putchar('-'),x=-x;
   if(x<10)putchar(x+'0');
   else write(x/10),putchar(x%10+'0');
}
int dp[N];
int n;
int a[N];
bool fl[N];
signed main(){
//	freopen("sequence.in","r",stdin);
//	freopen("sequence.out","w",stdout);
	n=read();
	int maxn=0;
	for(int i=1;i<=n;i++)a[i]=read(),dp[a[i]]=1,maxn=max(a[i],maxn),fl[a[i]]=1;
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		int x=a[i];
		for(int k=2;k*x<=maxn;k++){
			if(fl[k*x])dp[k*x]=max(dp[k*x],dp[x]+1);
		}
	}
	int ans=0;
	
	for(int i=1;i<=maxn;++i){
		if(fl[i])ans=max(ans,dp[i]);
	}
	cout<<ans<<"\n";
   return 0;
}
// ?????????????AC????
// ?????????????????????????
// ??????????????????
// ????????????????????????????????????
// ???????????????????????????????
// ????????????
// ????????????
// ????????????
// ????????????????????
// ????????????????????
// ????????????????????????????????
// ???????????????????????
// ???????????
// ?????????????
0