結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
noshi91
|
| 提出日時 | 2019-10-07 22:21:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 280 ms / 2,000 ms |
| コード長 | 1,354 bytes |
| コンパイル時間 | 824 ms |
| コンパイル使用メモリ | 78,000 KB |
| 実行使用メモリ | 21,504 KB |
| 最終ジャッジ日時 | 2024-10-14 18:00:01 |
| 合計ジャッジ時間 | 2,236 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <vector>
int main() {
using usize = std::size_t;
const auto chmin = [](usize &a, const usize b) {
if (b < a) {
a = b;
}
};
static constexpr usize ALim = 300001;
std::vector<usize> prime;
{
std::vector<bool> sieve(ALim, true);
for (usize i = 2; i != ALim; ++i) {
if (sieve[i]) {
prime.push_back(i);
for (usize j = i; j < ALim; j += i) {
sieve[j] = false;
}
}
}
}
usize n;
std::cin >> n;
std::vector<std::vector<usize>> rev(ALim);
std::vector<usize> dp(ALim, n);
for (usize i = 0; i != n; ++i) {
usize a;
std::cin >> a;
rev[a].push_back(i);
chmin(dp[a], i);
}
usize len = 0;
while (std::any_of(dp.cbegin(), dp.cend(), [n](usize x) { return x < n; })) {
++len;
std::vector<usize> exc(ALim, n);
for (const usize p : prime) {
for (usize i = 1; i * p < ALim; ++i) {
chmin(dp[i * p], dp[i]);
chmin(exc[i * p], dp[i]);
}
}
for (usize i = 1; i != ALim; ++i) {
usize j = 0;
const usize size = rev[i].size();
while (j != size && rev[i][j] <= exc[i]) {
++j;
}
if (j == size) {
dp[i] = n;
} else {
dp[i] = rev[i][j];
}
}
}
std::cout << len << std::endl;
}
noshi91