結果

問題 No.979 Longest Divisor Sequence
コンテスト
ユーザー Rumain831
提出日時 2026-11-18 10:56:57
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 209 ms / 2,000 ms
+ 712µs
コード長 527 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,285 ms
コンパイル使用メモリ 186,484 KB
実行使用メモリ 38,280 KB
最終ジャッジ日時 2026-11-18 10:57:04
合計ジャッジ時間 6,814 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main(void){
  int n; cin >> n;
  vector<vector<int>> d(3e5+5);
  vector<int> a(n);
  for(auto&x:a) cin >> x;
  for(int i=1; i<=3e5; i++){
    int now=i+i;
    while(now<=3e5) d[now].push_back(i), now+=i;
  }
  vector<int> dp(3e5+10, -1e9);
  dp[1]=0;
  for(int i=0; i<n; i++){
    int mx=0;
    for(auto x:d[a[i]]) mx=max(mx, dp[x]);
    dp[a[i]]=mx+1;
  }
  cout << *max_element(begin(dp), end(dp)) << endl;
  return 0; 
}
0