結果

問題 No.979 Longest Divisor Sequence
ユーザー tnakao0123tnakao0123
提出日時 2020-02-01 02:26:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 534 ms / 2,000 ms
コード長 1,030 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 95,020 KB
実行使用メモリ 4,992 KB
最終ジャッジ日時 2023-10-17 23:45:55
合計ジャッジ時間 2,503 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 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 2 ms
4,348 KB
testcase_10 AC 9 ms
4,988 KB
testcase_11 AC 9 ms
4,988 KB
testcase_12 AC 9 ms
4,988 KB
testcase_13 AC 27 ms
4,348 KB
testcase_14 AC 534 ms
4,992 KB
testcase_15 AC 179 ms
4,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 979.cc:  No.979 Longest Divisor Sequence - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300000;
const int MAX_A = 300000;

/* typedef */

/* global variables */

int dp[MAX_A + 1];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);

    int maxd = (ai > 1) ? dp[1] : 0;
    for (int p = 2; p * p <= ai; p++)
      if (ai % p == 0)
	setmax(maxd, max(dp[p], dp[ai / p]));

    setmax(dp[ai], maxd + 1);
  }

  int maxd = 0;
  for (int a = 1; a <= MAX_A; a++) setmax(maxd, dp[a]);

  printf("%d\n", maxd);
  return 0;
}
0