結果

問題 No.979 Longest Divisor Sequence
ユーザー konn13022konn13022
提出日時 2023-07-15 14:38:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 627 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 209,752 KB
実行使用メモリ 19,788 KB
最終ジャッジ日時 2023-10-16 23:47:54
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 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,648 KB
testcase_11 AC 8 ms
11,648 KB
testcase_12 AC 8 ms
11,648 KB
testcase_13 AC 51 ms
6,852 KB
testcase_14 WA -
testcase_15 AC 65 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]) {
        dp[to] = max(dp[to], dp[i] + 1);
      }
    }
    ans = max(ans, dp[i]);
    used[a[i]] = 1;
  }
  cout << ans << endl;

  return 0;
}
0