結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
a
|
| 提出日時 | 2016-07-08 23:50:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,092 bytes |
| コンパイル時間 | 575 ms |
| コンパイル使用メモリ | 58,692 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-13 07:34:54 |
| 合計ジャッジ時間 | 7,379 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 TLE * 1 -- * 12 |
ソースコード
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
int n;
long long a[111111];
int dp[111111];
bool is_p[1111111];
vector<long long> 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("%lld", 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;
}
a