結果

問題 No.390 最長の数列
ユーザー beetbeet
提出日時 2018-11-13 10:12:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 5,000 ms
コード長 957 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 207,208 KB
実行使用メモリ 19,676 KB
最終ジャッジ日時 2023-08-26 00:45:58
合計ジャッジ時間 3,380 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
18,580 KB
testcase_01 AC 9 ms
18,656 KB
testcase_02 AC 9 ms
18,580 KB
testcase_03 AC 8 ms
18,776 KB
testcase_04 AC 8 ms
18,680 KB
testcase_05 AC 45 ms
19,676 KB
testcase_06 AC 102 ms
19,504 KB
testcase_07 AC 8 ms
18,796 KB
testcase_08 AC 7 ms
18,544 KB
testcase_09 AC 8 ms
18,556 KB
testcase_10 AC 48 ms
19,520 KB
testcase_11 AC 50 ms
19,284 KB
testcase_12 AC 49 ms
19,488 KB
testcase_13 AC 38 ms
19,404 KB
testcase_14 AC 77 ms
19,500 KB
testcase_15 AC 6 ms
18,860 KB
testcase_16 AC 8 ms
18,848 KB
testcase_17 AC 8 ms
18,860 KB
testcase_18 AC 10 ms
18,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}



template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}

template<typename T>
map<T, Int> dict(const vector<T> &v){
  map<T, Int> res;
  for(Int i=0;i<(Int)v.size();i++)
    res[v[i]]=i;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n);
  for(Int i=0;i<n;i++) cin>>x[i];

  x=compress(x);
  
  const Int MAX = 1e6+100;
  const Int INF = 1e9;
  vector<Int> dp(MAX,-INF),ex(MAX,0);
  for(Int a:x) ex[a]=1;
  for(Int a:x){
    chmax(dp[a],1);
    for(Int b=a+a;b<MAX;b+=a)
      if(ex[b]) chmax(dp[b],dp[a]+1);
  }
  
  Int ans=0;
  for(Int i=0;i<MAX;i++) chmax(ans,dp[i]);
  cout<<ans<<endl;
  return 0;
}
0