結果

問題 No.390 最長の数列
ユーザー HaraTakashiHaraTakashi
提出日時 2022-01-30 18:09:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,482 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 209,780 KB
実行使用メモリ 54,820 KB
最終ジャッジ日時 2023-09-02 01:44:36
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
30,404 KB
testcase_01 AC 17 ms
30,276 KB
testcase_02 AC 24 ms
30,392 KB
testcase_03 AC 19 ms
30,268 KB
testcase_04 AC 22 ms
30,400 KB
testcase_05 AC 80 ms
35,076 KB
testcase_06 AC 1,482 ms
54,820 KB
testcase_07 AC 16 ms
30,280 KB
testcase_08 AC 12 ms
30,240 KB
testcase_09 AC 15 ms
30,220 KB
testcase_10 AC 275 ms
36,200 KB
testcase_11 AC 282 ms
35,976 KB
testcase_12 AC 266 ms
36,064 KB
testcase_13 AC 418 ms
34,028 KB
testcase_14 AC 498 ms
41,496 KB
testcase_15 AC 12 ms
30,332 KB
testcase_16 AC 10 ms
30,412 KB
testcase_17 AC 16 ms
30,432 KB
testcase_18 AC 20 ms
30,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
#define al(a) a.begin(), a.end()
#define ral(a) a.rbegin(), a.rend()
#define sz(a) (int)a.size()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define db(a, b) cout << #a << ": " << a << " " << #b << ": " << b << endl;

int main() {
  int n;
  cin >> n;
  set<int> s;
  rep(i, n) {
    int a;
    cin >> a;
    s.insert(a);
  }

  const int MX = 1000005;
  vector g(MX, vector<int>());
  for (auto a : s) {
    for (int x = a + a; x < MX; x += a) {
      if (s.count(x)) { g[a].push_back(x); }
    }
  }
  int ans = 0;
  vector<int> dp(MX, -1);
  auto dfs = [&](auto &f, int v) -> int {
    if (dp[v] != -1) return dp[v];
    int res = 1;
    for (auto u : g[v]) { res = max(res, f(f, u) + 1); }
    ans = max(ans, res);
    return dp[v] = res;
  };
  for (auto a : s) { dfs(dfs, a); }

  cout << ans << endl;
  return 0;
}
0