結果
| 問題 | No.390 最長の数列 |
| コンテスト | |
| ユーザー |
a
|
| 提出日時 | 2016-07-09 00:35:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 739 ms / 5,000 ms |
| コード長 | 707 bytes |
| 記録 | |
| コンパイル時間 | 1,023 ms |
| コンパイル使用メモリ | 56,448 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-02 10:38:02 |
| 合計ジャッジ時間 | 2,625 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
int n;
long long a[111111];
int dp[111111];
int solve(int p) {
if (dp[p] >= 0) return dp[p];
// printf("%d %d\n", p, it);
int res = 1;
for (size_t i = 2; i*a[p] <= 1000000; i++) {
int it = lower_bound(a+p, a+n, a[p]*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);
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