結果

問題 No.979 Longest Divisor Sequence
ユーザー risujirohrisujiroh
提出日時 2020-01-31 22:15:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 2,165 ms
コンパイル使用メモリ 172,636 KB
実行使用メモリ 39,424 KB
最終ジャッジ日時 2023-10-17 10:09:26
合計ジャッジ時間 8,103 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 325 ms
38,172 KB
testcase_01 AC 329 ms
38,172 KB
testcase_02 AC 345 ms
38,172 KB
testcase_03 AC 325 ms
38,172 KB
testcase_04 AC 333 ms
38,172 KB
testcase_05 AC 337 ms
38,172 KB
testcase_06 AC 338 ms
38,172 KB
testcase_07 AC 334 ms
38,172 KB
testcase_08 AC 329 ms
38,172 KB
testcase_09 AC 326 ms
38,172 KB
testcase_10 AC 345 ms
38,172 KB
testcase_11 AC 334 ms
38,172 KB
testcase_12 AC 361 ms
38,172 KB
testcase_13 AC 370 ms
39,424 KB
testcase_14 AC 396 ms
39,424 KB
testcase_15 AC 359 ms
38,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

auto chmax = [](auto&& l, auto r) { return l < r ? l = r, 1 : 0; };

constexpr int lim = 3e5, th = lim + 1;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for_each(begin(a), end(a), [](int& e) { cin >> e; });
  reverse(begin(a), end(a));
  vector<vector<int>> ds(lim + 1);
  for (int d = 1; d < th; ++d) {
    for (int i = 2 * d; i <= lim; i += d) {
      ds[i].push_back(d);
    }
  }
  vector<int> dp(lim + 1), m(th);
  for (int e : a) {
    int mx = -1;
    if (e < th) {
      mx = m[e];
    } else {
      for (int i = 2 * e; i <= lim; i += e) {
        chmax(mx, dp[i]);
      }
    }
    chmax(dp[e], mx + 1);
    for (int d : ds[e]) {
      chmax(m[d], dp[e]);
    }
  }
  cout << *max_element(begin(dp), end(dp)) << '\n';
}
0