結果

問題 No.979 Longest Divisor Sequence
ユーザー kk
提出日時 2021-04-03 02:28:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 585 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 200,616 KB
実行使用メモリ 38,048 KB
最終ジャッジ日時 2023-08-25 17:25:42
合計ジャッジ時間 9,520 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 360 ms
37,144 KB
testcase_01 AC 420 ms
37,108 KB
testcase_02 AC 377 ms
37,116 KB
testcase_03 AC 364 ms
37,124 KB
testcase_04 AC 355 ms
37,088 KB
testcase_05 AC 371 ms
37,364 KB
testcase_06 AC 353 ms
37,144 KB
testcase_07 AC 358 ms
37,120 KB
testcase_08 AC 349 ms
37,080 KB
testcase_09 AC 393 ms
37,132 KB
testcase_10 AC 366 ms
37,160 KB
testcase_11 AC 375 ms
37,176 KB
testcase_12 AC 366 ms
37,120 KB
testcase_13 AC 401 ms
38,040 KB
testcase_14 AC 452 ms
38,048 KB
testcase_15 AC 382 ms
37,184 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