結果

問題 No.390 最長の数列
ユーザー umezoumezo
提出日時 2022-08-12 20:30:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 581 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 202,580 KB
実行使用メモリ 11,020 KB
最終ジャッジ日時 2023-10-24 06:11:41
合計ジャッジ時間 4,344 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
11,020 KB
testcase_01 AC 10 ms
11,020 KB
testcase_02 AC 10 ms
11,020 KB
testcase_03 AC 10 ms
11,020 KB
testcase_04 AC 10 ms
11,020 KB
testcase_05 AC 18 ms
11,020 KB
testcase_06 AC 39 ms
11,020 KB
testcase_07 AC 9 ms
11,020 KB
testcase_08 AC 8 ms
11,020 KB
testcase_09 AC 9 ms
11,020 KB
testcase_10 AC 31 ms
11,020 KB
testcase_11 AC 31 ms
11,020 KB
testcase_12 AC 31 ms
11,020 KB
testcase_13 AC 24 ms
11,020 KB
testcase_14 AC 44 ms
11,020 KB
testcase_15 AC 9 ms
11,020 KB
testcase_16 AC 8 ms
11,020 KB
testcase_17 AC 10 ms
11,020 KB
testcase_18 AC 10 ms
11,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MAX=1e6;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  cin>>n;
  vector<int> A(MAX+1),dp(MAX+1);
  rep(i,n){
    int x;
    cin>>x;
    A[x]=1;
    dp[x]=1;
  }
  for(int i=1;i<=MAX;i++){
    if(A[i]){
      for(int j=2*i;j<=MAX;j+=i) dp[j]=max(dp[j],dp[i]+1);
    }
  }
  int ma=0;
  for(int i=1;i<=MAX;i++){
    if(A[i]) ma=max(ma,dp[i]);
  }
  cout<<ma<<endl;
  
  return 0;
}
0