結果

問題 No.979 Longest Divisor Sequence
ユーザー tonegawatonegawa
提出日時 2020-02-01 00:40:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,317 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 96,140 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-10-17 15:07:37
合計ジャッジ時間 3,448 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll ans = 0, n;std::cin >> n;
  vll dp(300001, 0), a(n);
  re(i, n) std::cin >> a[i];
  for(int i=n-1;i>=0;i--){
    ll t = dp[a[i]]+1;
    ans = max(ans, t);
    for(int j=2;j*j<=a[i];j++){
      if(a[i]%j==0){
        dp[j] = max(dp[j], t);
        dp[a[i]/j] = max(dp[a[i]/j], t);
      }
    }
    if(a[i]!=1) dp[1] = max(dp[1], t);
  }
  std::cout << ans << '\n';
  return 0;
}
0