結果

問題 No.979 Longest Divisor Sequence
ユーザー utouto97utouto97
提出日時 2020-02-07 01:28:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,124 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 166,796 KB
実行使用メモリ 6,008 KB
最終ジャッジ日時 2023-10-25 22:57:15
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 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 1 ms
4,348 KB
testcase_10 AC 15 ms
6,000 KB
testcase_11 AC 16 ms
5,996 KB
testcase_12 AC 15 ms
6,004 KB
testcase_13 AC 25 ms
4,348 KB
testcase_14 AC 1,124 ms
6,008 KB
testcase_15 AC 377 ms
6,008 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>;

int dp[301010];

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

  int ans = 0;
  rep(i, 0, n){
    int a; 
    scanf("%d", &a);

    int ma = 1;
    for(int j = 1; j*j <= a; j++) if(a%j == 0){
      if(a != 1) chmax(ma, dp[j]+1);
      if(j > 1) chmax(ma, dp[a/j]+1);
    }
    chmax(dp[a], ma);
    chmax(ans, ma);
  }
  cout << ans << endl;

  return 0;
}
0