結果

問題 No.979 Longest Divisor Sequence
ユーザー beetbeet
提出日時 2020-01-31 21:55:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 666 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 206,084 KB
実行使用メモリ 38,276 KB
最終ジャッジ日時 2023-10-17 09:35:13
合計ジャッジ時間 8,636 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 336 ms
37,288 KB
testcase_01 AC 284 ms
37,288 KB
testcase_02 AC 333 ms
37,288 KB
testcase_03 AC 303 ms
37,288 KB
testcase_04 AC 304 ms
37,288 KB
testcase_05 AC 323 ms
37,288 KB
testcase_06 AC 289 ms
37,288 KB
testcase_07 AC 269 ms
37,288 KB
testcase_08 AC 274 ms
37,288 KB
testcase_09 AC 307 ms
37,288 KB
testcase_10 AC 346 ms
37,288 KB
testcase_11 AC 357 ms
37,288 KB
testcase_12 AC 342 ms
37,288 KB
testcase_13 AC 381 ms
38,276 KB
testcase_14 AC 466 ms
38,276 KB
testcase_15 AC 394 ms
37,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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