結果

問題 No.979 Longest Divisor Sequence
ユーザー noshi91noshi91
提出日時 2019-10-07 21:46:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 893 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 77,164 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 17:50:28
合計ジャッジ時間 2,524 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 44 ms
6,940 KB
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  static constexpr int ALim = 20;
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (auto &e : a) {
    std::cin >> e;
  }
  std::vector<std::vector<int>> rev(ALim);
  std::vector<int> dp(ALim, -1);
  for (int i = 0; i != n; ++i) {
    rev[a[i]].push_back(i);
    dp[a[i]] = i;
  }
  for (int len = 1;; ++len) {
    for (int i = 1; i != ALim; ++i) {
      int max = -1;
      for (int j = i + i; j < ALim; j += i) {
        max = std::max(max, dp[j]);
      }
      int j = 0;
      while (j != static_cast<int>(rev[i].size()) && rev[i][j] < max) {
        ++j;
      }
      if (j == 0) {
        dp[i] = -1;
      } else {
        dp[i] = rev[i][j - 1];
      }
    }
    if (std::all_of(dp.cbegin(), dp.cend(), [](int x) { return x == -1; })) {
      std::cout << len << std::endl;
      return 0;
    }
  }
}
0