結果

問題 No.979 Longest Divisor Sequence
ユーザー konn13022konn13022
提出日時 2023-07-15 14:18:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 639 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 209,800 KB
実行使用メモリ 19,792 KB
最終ジャッジ日時 2023-10-16 23:26:11
合計ジャッジ時間 3,498 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 AC 1 ms
4,348 KB
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 2 ms
4,348 KB
testcase_10 AC 8 ms
11,644 KB
testcase_11 AC 8 ms
11,644 KB
testcase_12 AC 8 ms
11,644 KB
testcase_13 AC 51 ms
6,848 KB
testcase_14 WA -
testcase_15 AC 68 ms
15,076 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<vector<int>> ids(mx + 1);
  for (int i = 0; i < n; i++) {
    ids[a[i]].push_back(i);
  }

  vector<int> dp(n, 1), used(mx + 1);
  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]) {
      for (int to : ids[j]) {
        if (i < to && to < n) dp[to] = max(dp[to], dp[i] + 1);
      }
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;

  return 0;
}
0