結果
| 問題 | No.390 最長の数列 | 
| コンテスト | |
| ユーザー |  umezo | 
| 提出日時 | 2022-08-12 20:30:59 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 70 ms / 5,000 ms | 
| コード長 | 581 bytes | 
| コンパイル時間 | 1,959 ms | 
| コンパイル使用メモリ | 194,768 KB | 
| 最終ジャッジ日時 | 2025-01-30 20:35:11 | 
| ジャッジサーバーID (参考情報) | judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 15 | 
ソースコード
#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;
}
            
            
            
        