結果

問題 No.979 Longest Divisor Sequence
ユーザー utouto97utouto97
提出日時 2020-02-07 00:50:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 843 bytes
コンパイル時間 2,659 ms
コンパイル使用メモリ 161,372 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-10-25 22:53:59
合計ジャッジ時間 6,886 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,416 KB
testcase_01 AC 4 ms
5,416 KB
testcase_02 AC 3 ms
5,416 KB
testcase_03 AC 3 ms
5,416 KB
testcase_04 AC 3 ms
5,416 KB
testcase_05 AC 3 ms
5,416 KB
testcase_06 AC 3 ms
5,416 KB
testcase_07 AC 4 ms
5,416 KB
testcase_08 AC 4 ms
5,416 KB
testcase_09 AC 4 ms
5,416 KB
testcase_10 AC 27 ms
5,416 KB
testcase_11 AC 27 ms
5,416 KB
testcase_12 AC 27 ms
5,416 KB
testcase_13 AC 52 ms
7,792 KB
testcase_14 TLE -
testcase_15 AC 783 ms
6,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

signed main() {
  int n;
  cin >> n;

  vi a(n);
  rep(i, 0, n) cin >> a[i];

  vi dp(301010);
  int ans = 0;
  rep(i, 0, n){
    int ma = 1;
    rep(j, 1, a[i]/j+1) if(a[i]%j == 0){
      if(a[i] != 1) chmax(ma, dp[j]+1);
      if(j > 1) chmax(ma, dp[a[i]/j]+1);
    }
    chmax(dp[a[i]], ma);
    chmax(ans, ma);
  }
  cout << ans << endl;

  return 0;
}
0