結果

問題 No.979 Longest Divisor Sequence
ユーザー tnakao0123tnakao0123
提出日時 2020-02-01 02:23:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,015 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 95,040 KB
実行使用メモリ 5,040 KB
最終ジャッジ日時 2023-10-17 23:41:00
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
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 3 ms
4,348 KB
testcase_10 AC 8 ms
5,036 KB
testcase_11 AC 8 ms
5,036 KB
testcase_12 AC 8 ms
5,036 KB
testcase_13 WA -
testcase_14 AC 447 ms
5,040 KB
testcase_15 AC 151 ms
5,036 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 = dp[1];
    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