結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-29 17:29:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 5,000 ms |
| コード長 | 774 bytes |
| コンパイル時間 | 1,093 ms |
| コンパイル使用メモリ | 83,676 KB |
| 最終ジャッジ日時 | 2025-01-10 16:14:13 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
constexpr int X = 1000000;
void solve() {
int n;
std::cin >> n;
std::vector<int> xs(n);
for (auto& x : xs) std::cin >> x;
std::sort(xs.rbegin(), xs.rend());
std::vector<int> pos(X + 1, -1);
for (int i = 0; i < n; ++i) pos[xs[i]] = i;
std::vector<int> dp(n, 1);
for (int i = 0; i < n; ++i) {
auto x = xs[i];
for (int y = x * 2; y <= xs.front(); y += x) {
if (pos[y] == -1) continue;
dp[i] = std::max(dp[i], dp[pos[y]] + 1);
}
}
std::cout << *std::max_element(dp.begin(), dp.end()) << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}