結果

問題 No.390 最長の数列
ユーザー kk
提出日時 2020-09-05 09:28:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 470 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 202,640 KB
実行使用メモリ 7,540 KB
最終ジャッジ日時 2023-08-18 13:40:30
合計ジャッジ時間 3,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,868 KB
testcase_01 AC 5 ms
6,872 KB
testcase_02 AC 5 ms
6,984 KB
testcase_03 AC 4 ms
7,012 KB
testcase_04 AC 6 ms
6,880 KB
testcase_05 AC 20 ms
7,280 KB
testcase_06 AC 31 ms
7,524 KB
testcase_07 AC 4 ms
6,992 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 5 ms
7,080 KB
testcase_10 AC 23 ms
7,272 KB
testcase_11 AC 23 ms
7,504 KB
testcase_12 AC 23 ms
7,472 KB
testcase_13 AC 17 ms
7,272 KB
testcase_14 AC 44 ms
7,540 KB
testcase_15 AC 4 ms
6,924 KB
testcase_16 AC 4 ms
6,888 KB
testcase_17 AC 4 ms
6,948 KB
testcase_18 AC 4 ms
6,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

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

  int n;
  cin >> n;
  vector<int> x(n);
  REP (i, n) cin >> x[i];
  sort(x.begin(), x.end());

  vector<int> dp(1000000+1);  
  int ret = 0;
  for (int a: x) {
    ret = max(ret, ++dp[a]);
    for (int b = 2 * a; b <= 1000000; b += a)
      dp[b] = max(dp[b], dp[a]);
  }

  cout << ret << endl;
  
  return 0;
}
0