結果
| 問題 |
No.390 最長の数列
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-04-18 16:55:59 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 438 ms / 5,000 ms |
| コード長 | 1,308 bytes |
| コンパイル時間 | 3,298 ms |
| コンパイル使用メモリ | 280,804 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-18 16:56:05 |
| 合計ジャッジ時間 | 5,614 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
int dp[N];
signed main(){
cin>>n;
for(int i=0;i<=n;i++)
dp[i]=1;
vector<int>x(n);
vector<int>p(n);
for(int i=0;i<n;i++)
cin>>x[i];
sort(x.begin(),x.end());
for(int i=1;i<n;i++)
if(x[i]==x[i-1])
x[i-1]=0;
sort(x.begin(),x.end());
int now=-1;
for(int i=0;i<n;i++){
if(x[i]!=0){
now++;
p[now]=x[i];
}
}
n=p.size();
int ans=0;
for(int i=0;i<n;i++){
int k=p[i];
int hao=1;
for(int d=1;d*d<=k;d++){
if(k%d==0){
if(d<k){
auto lp=lower_bound(p.begin(),p.end(),d);
if(lp!=p.end()&&*lp==d){
int j=lp-p.begin();
hao=max(hao,dp[j]+1);
}
}
int t=k/d;
if(t!=d&&t<k){
auto lp=lower_bound(p.begin(),p.end(),t);
if(lp!=p.end()&&*lp==t){
int j=lp-p.begin();
hao=max(hao,dp[j]+1);
}
}
}
}
dp[i]=hao;
ans=max(hao,ans);
}
cout<<ans;
return 0;
}
vjudge1