結果

問題 No.979 Longest Divisor Sequence
コンテスト
ユーザー beet
提出日時 2020-01-31 21:55:39
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 666 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,571 ms
コンパイル使用メモリ 215,064 KB
実行使用メモリ 38,400 KB
最終ジャッジ日時 2026-06-08 16:06:55
合計ジャッジ時間 7,499 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;}

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

  const int MAX = 3e5 + 100;
  vector< vector<int> > G(MAX);
  for(int i=1;i<MAX;i++)
    for(int j=i+i;j<MAX;j+=i)
      G[j].emplace_back(i);

  vector<int> dp(MAX,-MAX);
  int ans=0;
  for(int a:as){
    chmax(dp[a],1);
    for(int d:G[a])
      chmax(dp[a],dp[d]+1);
    chmax(ans,dp[a]);
  }
  cout<<ans<<endl;
  return 0;
}
0