結果

問題 No.979 Longest Divisor Sequence
ユーザー snow39snow39
提出日時 2020-01-31 22:00:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,296 ms / 2,000 ms
コード長 765 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 94,044 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2023-10-17 09:41:38
合計ジャッジ時間 3,264 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 16 ms
4,880 KB
testcase_11 AC 17 ms
4,880 KB
testcase_12 AC 17 ms
4,876 KB
testcase_13 AC 51 ms
5,820 KB
testcase_14 AC 1,296 ms
6,948 KB
testcase_15 AC 432 ms
5,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int dp[300030];

int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  for(int i=0;i<N;i++){
    ll val=A[i];
    for(ll j=1;j*j<=val;j++){
      if(val%j!=0) continue;
      if(j!=val) dp[A[i]]=max(dp[A[i]],dp[j]+1);
      if(val/j!=val) dp[A[i]]=max(dp[A[i]],dp[val/j]+1);
    }
    dp[A[i]]=max(dp[A[i]],1);
  }

  int ans=1;
  for(int i=1;i<=300010;i++) ans=max(ans,dp[i]);
  cout<<ans<<endl;

  return 0;
}
0