結果
| 問題 |
No.390 最長の数列
|
| ユーザー |
vjudge1
|
| 提出日時 | 2025-04-18 16:55:35 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,386 bytes |
| コンパイル時間 | 3,227 ms |
| コンパイル使用メモリ | 278,976 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-18 16:55:40 |
| 合計ジャッジ時間 | 4,183 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | freopen("sequence.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:8:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | freopen("sequence.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
int dp[N];
signed main(){
freopen("sequence.in","r",stdin);
freopen("sequence.out","w",stdout);
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