結果

問題 No.390 最長の数列
ユーザー aa
提出日時 2016-07-08 23:45:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,078 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 59,420 KB
実行使用メモリ 12,496 KB
最終ジャッジ日時 2024-04-21 08:39:42
合計ジャッジ時間 7,104 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,248 KB
testcase_01 AC 6 ms
5,376 KB
testcase_02 AC 6 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 27 ms
5,552 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

int n;
int a[111111];
int dp[111111];
bool is_p[1111111];
vector<int> lis;

int solve(int p) {
  // int it = lower_bound(a+p, a+n, a[p]*2) - a;
  // if (dp[p] >= 0) return dp[p];
  // printf("%d %d\n", p, it);
  int res = 1;
  // for (int i = it; i < n; i++) {
  for (size_t i = 0; i < lis.size(); i++) {
    int it = lower_bound(a+p, a+n, a[p]*lis[i]) - a;
    if (it >= n) break;
    if (a[it]%a[p] == 0) {
      res = max(res, solve(it)+1);
    }
  }
    //}
  return dp[p] = res;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a+i);

  for (int i = 2; i*i <= 1000000; i++) {
    if (!is_p[i]) {
      for (int j = i*i; j <= 1000000; j+=i) {
        is_p[j] = true;
      }
    }
  }
  for (int i = 2; i < 1000000; i++) {
    if (!is_p[i]) {
      lis.push_back(i);
    }
  }
  
  sort(a, a+n);

  int res = 0;
  fill(dp, dp+n+1, -1);
  for (int i = 0; i < n; i++) {
    res = max(res, solve(i));
  }

  printf("%d\n", res);
  return 0;
}
0