結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-29 17:28:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,234 ms / 5,000 ms |
| コード長 | 738 bytes |
| コンパイル時間 | 1,553 ms |
| コンパイル使用メモリ | 89,664 KB |
| 最終ジャッジ日時 | 2025-01-10 16:14:05 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
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::map<int, int> pos;
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.count(y)) 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;
}