結果

問題 No.390 最長の数列
ユーザー HaraTakashiHaraTakashi
提出日時 2022-01-30 19:47:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 5,000 ms
コード長 1,470 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 199,732 KB
実行使用メモリ 7,236 KB
最終ジャッジ日時 2023-09-02 01:46:49
合計ジャッジ時間 3,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,924 KB
testcase_01 AC 5 ms
6,924 KB
testcase_02 AC 5 ms
6,876 KB
testcase_03 AC 4 ms
6,868 KB
testcase_04 AC 5 ms
6,976 KB
testcase_05 AC 31 ms
6,868 KB
testcase_06 AC 49 ms
6,932 KB
testcase_07 AC 4 ms
7,236 KB
testcase_08 AC 4 ms
7,236 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 35 ms
6,936 KB
testcase_11 AC 35 ms
6,916 KB
testcase_12 AC 35 ms
6,972 KB
testcase_13 AC 31 ms
6,972 KB
testcase_14 AC 53 ms
6,868 KB
testcase_15 AC 3 ms
7,052 KB
testcase_16 AC 4 ms
7,020 KB
testcase_17 AC 5 ms
7,052 KB
testcase_18 AC 5 ms
7,012 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;
  const int MX = 1000005;
  vector<int> dp(MX);
  rep(i, n) {
    int a;
    cin >> a;
    dp[a] = 1;
  }

  int ans = 0;
  drep(i, MX) {
    if (!dp[i]) continue;
    for (int x = i + i; x < MX; x += i) { dp[i] = max(dp[i], dp[x] + 1); }
    ans = max(ans, dp[i]);
  }
  cout << ans << 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