結果

問題 No.979 Longest Divisor Sequence
ユーザー nakaken88nakaken88
提出日時 2020-02-01 16:42:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,284 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 169,376 KB
実行使用メモリ 8,012 KB
最終ジャッジ日時 2023-10-19 00:07:25
合計ジャッジ時間 4,019 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,636 KB
testcase_01 AC 4 ms
5,636 KB
testcase_02 AC 4 ms
5,636 KB
testcase_03 AC 4 ms
5,636 KB
testcase_04 AC 4 ms
5,636 KB
testcase_05 AC 4 ms
5,636 KB
testcase_06 AC 4 ms
5,636 KB
testcase_07 AC 4 ms
5,636 KB
testcase_08 AC 4 ms
5,636 KB
testcase_09 AC 4 ms
5,636 KB
testcase_10 AC 17 ms
5,636 KB
testcase_11 AC 17 ms
5,636 KB
testcase_12 AC 17 ms
5,636 KB
testcase_13 AC 26 ms
8,012 KB
testcase_14 AC 1,284 ms
8,012 KB
testcase_15 AC 427 ms
6,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  vector<ll> dp(300005, 0);

  for (int i = 0; i < N; i++) {
    ll t = A[i], temp = 0;
    for (int j = 1; j <= sqrt(t); j++) {
      if (t % j) continue;
      ll f1 = j, f2 = t / j;
      if (f1 < t) temp = max(temp, dp[f1]);
      if (f2 < t) temp = max(temp, dp[f2]);
    }
    dp[t] = temp + 1;
  }

  ll ans = 0;
  for (int i = 0; i < 300005; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}
0