結果

問題 No.979 Longest Divisor Sequence
ユーザー ngtkanangtkana
提出日時 2019-10-06 21:42:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 200,292 KB
実行使用メモリ 38,144 KB
最終ジャッジ日時 2024-04-19 13:53:41
合計ジャッジ時間 4,071 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 275 ms
36,864 KB
testcase_11 AC 272 ms
37,108 KB
testcase_12 AC 300 ms
36,956 KB
testcase_13 AC 18 ms
5,376 KB
testcase_14 AC 363 ms
38,144 KB
testcase_15 AC 301 ms
37,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};

auto divisors(int n) {
  auto ret = std::vector< std::vector< int > >(n);
  for (auto i = 1; i < n; i++) {
    for (auto j = i; j < n; j += i) {
      ret.at(j).emplace_back(i);
    }
  }
  return ret;
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector< int > a(n);
  for (auto & x : a) std::cin >> x;
  auto max = *std::max_element(all(a));
  auto divs = divisors(max + 1);

  std::vector< int > lds(max + 1, 0);
  for (auto x : a) {
    if (x == 1) {
      cmx(lds.at(x), 1);
      continue;
    }
    for (auto y : divs.at(x)) {
      if (x == y) continue;
      cmx(lds.at(x), lds.at(y) + 1);
    }
  }
  auto ret = *std::max_element(all(lds));
  std::cout << ret << std::endl;
  return 0;
}
0