結果

問題 No.979 Longest Divisor Sequence
ユーザー set0gut1set0gut1
提出日時 2020-01-31 22:24:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,623 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 92,844 KB
実行使用メモリ 13,344 KB
最終ジャッジ日時 2023-10-17 10:28:17
合計ジャッジ時間 4,002 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 17 ms
4,348 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 22 ms
4,348 KB
testcase_14 AC 1,623 ms
13,344 KB
testcase_15 AC 529 ms
9,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;

  unordered_map<ll, ll> memo;

  rep (i, N) {
    ll A;
    cin >> A;
    if (A == 1) memo[1] = 1;
    else if (memo[A] == 0 or memo[A] == 1) memo[A] = memo[1] + 1;
    for (ll it = 2; it * it <= A; it++) {
      if (A % it) continue;
      ll tmp = max(memo[it] + 1, memo[A / it] + 1);
      if (tmp > memo[A]) memo[A] = tmp;
    }
  }

  ll ans = 0;
  for (auto it: memo) if (ans < it.second) ans = it.second;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}
0