結果

問題 No.979 Longest Divisor Sequence
ユーザー oxyshoweroxyshower
提出日時 2020-02-01 16:14:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 580 bytes
コンパイル時間 1,571 ms
コンパイル使用メモリ 170,084 KB
実行使用メモリ 8,096 KB
最終ジャッジ日時 2023-10-19 00:06:18
合計ジャッジ時間 4,257 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,720 KB
testcase_01 AC 4 ms
5,720 KB
testcase_02 AC 4 ms
5,720 KB
testcase_03 AC 4 ms
5,720 KB
testcase_04 WA -
testcase_05 AC 4 ms
5,720 KB
testcase_06 AC 4 ms
5,720 KB
testcase_07 AC 4 ms
5,720 KB
testcase_08 AC 4 ms
5,720 KB
testcase_09 AC 4 ms
5,720 KB
testcase_10 AC 18 ms
5,720 KB
testcase_11 AC 18 ms
5,720 KB
testcase_12 AC 17 ms
5,720 KB
testcase_13 WA -
testcase_14 AC 1,322 ms
8,096 KB
testcase_15 AC 446 ms
6,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  vector<int> dp(3e5+1, 0);
  for(int i = 0; i < n; i++){
    for(int j = 1; j*j <= a[i]; j++){
      if(a[i] % j == 0){
        dp[a[i]] = max(dp[a[i]], dp[j] + 1);
        if(j != 1) dp[a[i]] = max(dp[a[i]], dp[a[i] / j] + 1);
      }
    }
    dp[a[i]] = max(dp[a[i]], 1LL);
  }
  cout << *max_element(dp.begin(),dp.end()) << endl;

  return 0;
}
0