結果

問題 No.979 Longest Divisor Sequence
ユーザー 杨娵隅杨娵隅
提出日時 2021-11-16 17:02:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 585 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 202,232 KB
実行使用メモリ 38,104 KB
最終ジャッジ日時 2023-08-22 17:13:10
合計ジャッジ時間 10,032 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 407 ms
37,368 KB
testcase_01 AC 407 ms
37,248 KB
testcase_02 AC 400 ms
37,092 KB
testcase_03 AC 386 ms
37,208 KB
testcase_04 AC 401 ms
37,148 KB
testcase_05 AC 396 ms
37,244 KB
testcase_06 AC 411 ms
37,172 KB
testcase_07 AC 414 ms
37,212 KB
testcase_08 AC 405 ms
37,180 KB
testcase_09 AC 379 ms
37,100 KB
testcase_10 AC 398 ms
37,408 KB
testcase_11 AC 375 ms
37,132 KB
testcase_12 AC 379 ms
37,244 KB
testcase_13 AC 414 ms
37,940 KB
testcase_14 AC 427 ms
38,104 KB
testcase_15 AC 432 ms
37,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int N = 300000;
int dp[N+1];
vector<int> divisor[N+1];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 1; i <= N; i++) {
    for (int j = 1; i*j <= N; j++)
      divisor[i*j].push_back(i);
  }

  for (int x: a) {
    int mx = 0;
    for (int d: divisor[x]) {
      if (d < x) {
        mx = max(mx, dp[d]);
      }
    }
    dp[x] = ++mx;
  }

  cout << *max_element(dp, dp + N + 1) << endl;
  
  
  return 0;
}
0