結果
問題 |
No.390 最長の数列
|
ユーザー |
![]() |
提出日時 | 2016-07-09 10:39:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 65 ms / 5,000 ms |
コード長 | 816 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 48,512 KB |
実行使用メモリ | 7,552 KB |
最終ジャッジ日時 | 2024-10-02 10:40:53 |
合計ジャッジ時間 | 1,456 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d",x+i); | ~~~~~^~~~~~~~~~
ソースコード
// #include <bits/stdc++.h> #include <stdio.h> #include <vector> #include <algorithm> #include <functional> using namespace std; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) int n; int x[125252]; int dp[1<<20]; int main(){ vector<bool> has(1<<20,false); int ans = 1; scanf("%d",&n); REP(i,n){ scanf("%d",x+i); has[x[i]] = true; } sort(x,x+n,greater<int>()); REP(i,n){ int y = x[i]; int it = y; if(dp[y]==0)dp[y]=1; for(int it=2*y;it<(1<<20);it+=y){ if(!has[it])continue; if(dp[y]<=dp[it])dp[y]=dp[it]+1; } if(ans<dp[y])ans=dp[y]; } printf("%d\n",ans); return 0; }