結果

問題 No.979 Longest Divisor Sequence
ユーザー konn13022konn13022
提出日時 2023-07-15 14:55:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 2,295 ms
コンパイル使用メモリ 209,604 KB
実行使用メモリ 19,764 KB
最終ジャッジ日時 2023-10-17 00:05:42
合計ジャッジ時間 3,348 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 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 8 ms
11,648 KB
testcase_11 AC 7 ms
11,648 KB
testcase_12 AC 7 ms
11,648 KB
testcase_13 AC 51 ms
6,852 KB
testcase_14 AC 220 ms
19,764 KB
testcase_15 AC 64 ms
15,080 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);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = a[i] * 2; j <= mx; j += a[i]) {
      // if (used[a[i]]) break;
      for (int to : ids[j]) {
        if (i < to) dp[to] = max(dp[to], dp[i] + 1);
      }
    }
    ans = max(ans, dp[i]);
    used[a[i]] = 1;
  }
  cout << ans << endl;

  return 0;
}
0