結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
ngtkana
|
| 提出日時 | 2019-10-06 21:42:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 383 ms / 2,000 ms |
| コード長 | 891 bytes |
| コンパイル時間 | 2,419 ms |
| コンパイル使用メモリ | 199,604 KB |
| 最終ジャッジ日時 | 2025-01-07 21:09:22 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
auto divisors(int n) {
auto ret = std::vector< std::vector< int > >(n);
for (auto i = 1; i < n; i++) {
for (auto j = i; j < n; j += i) {
ret.at(j).emplace_back(i);
}
}
return ret;
}
int main() {
std::cin.tie(0); std::cin.sync_with_stdio(false);
int n; std::cin >> n;
std::vector< int > a(n);
for (auto & x : a) std::cin >> x;
auto max = *std::max_element(all(a));
auto divs = divisors(max + 1);
std::vector< int > lds(max + 1, 0);
for (auto x : a) {
if (x == 1) {
cmx(lds.at(x), 1);
continue;
}
for (auto y : divs.at(x)) {
if (x == y) continue;
cmx(lds.at(x), lds.at(y) + 1);
}
}
auto ret = *std::max_element(all(lds));
std::cout << ret << std::endl;
return 0;
}
ngtkana