結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
noshi91
|
| 提出日時 | 2019-10-07 21:46:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 893 bytes |
| コンパイル時間 | 886 ms |
| コンパイル使用メモリ | 75,296 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-14 16:58:24 |
| 合計ジャッジ時間 | 3,289 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 RE * 5 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
static constexpr int ALim = 20;
int n;
std::cin >> n;
std::vector<int> a(n);
for (auto &e : a) {
std::cin >> e;
}
std::vector<std::vector<int>> rev(ALim);
std::vector<int> dp(ALim, -1);
for (int i = 0; i != n; ++i) {
rev[a[i]].push_back(i);
dp[a[i]] = i;
}
for (int len = 1;; ++len) {
for (int i = 1; i != ALim; ++i) {
int max = -1;
for (int j = i + i; j < ALim; j += i) {
max = std::max(max, dp[j]);
}
int j = 0;
while (j != static_cast<int>(rev[i].size()) && rev[i][j] < max) {
++j;
}
if (j == 0) {
dp[i] = -1;
} else {
dp[i] = rev[i][j - 1];
}
}
if (std::all_of(dp.cbegin(), dp.cend(), [](int x) { return x == -1; })) {
std::cout << len << std::endl;
return 0;
}
}
}
noshi91