結果

問題 No.390 最長の数列
ユーザー Mr.SpockMr.Spock
提出日時 2020-11-10 23:47:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 691 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 169,628 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2023-09-30 00:16:28
合計ジャッジ時間 3,145 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 22 ms
7,364 KB
testcase_06 AC 47 ms
7,176 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 5 ms
6,920 KB
testcase_09 AC 6 ms
6,900 KB
testcase_10 AC 27 ms
7,492 KB
testcase_11 AC 27 ms
7,232 KB
testcase_12 AC 27 ms
7,528 KB
testcase_13 AC 20 ms
7,184 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
6,872 KB
testcase_17 AC 6 ms
7,000 KB
testcase_18 AC 7 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int>v(n + 1);
  int nax = 0;
  for (int i = 1 ; i <= n; i++) {
    cin >> v[i];
    nax = max(nax, v[i]);
  }
  nax += 10;
  sort(v.begin(), v.end());
  vector<int>dp(nax + 1, 0);
  for (int i = 1; i <= n; i++) {
    dp[v[i]] = 1;
  }
  for (int i = 1; i < nax; i++) {
    if (dp[i] == 0)continue;
    for (int j = 2 * i; j < nax; j += i) {
      if (dp[j] >= 1) {
        dp[j] = max(dp[j], 1 + dp[i]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= nax; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
0