結果

問題 No.979 Longest Divisor Sequence
ユーザー konn13022konn13022
提出日時 2023-07-15 14:10:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 611 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 207,092 KB
実行使用メモリ 8,084 KB
最終ジャッジ日時 2023-10-16 23:16:31
合計ジャッジ時間 3,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
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 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 5 ms
5,708 KB
testcase_11 AC 4 ms
5,708 KB
testcase_12 AC 4 ms
5,708 KB
testcase_13 AC 50 ms
5,708 KB
testcase_14 AC 116 ms
8,084 KB
testcase_15 AC 42 ms
6,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  int mx = *max_element(a.begin(), a.end());
  vector<int> dp(n, 1), used(mx + 1), min_id(mx + 1, n);
  for (int i = 0; i < n; i++) {
    min_id[a[i]] = min(min_id[a[i]], i);
  }

  for (int i = 0; i < n; i++) {
    if (used[a[i]]) continue;
    used[a[i]] = 1;
    for (int j = a[i] * 2; j <= mx; j += a[i]) {
      int to = min_id[j];
      if (to < n) dp[to] = max(dp[to], dp[i] + 1);
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;

  return 0;
}
0